譬如我在某个test类里面定义2个test methods:@Test public void testA(){}
@Test public void testB(){}
我怎么保证每次运行的时候testA()都在testB()之前执行?如果JUnit根本没有这个特性,为什么它的设计者不设计者个特性?
@Test public void testB(){}
我怎么保证每次运行的时候testA()都在testB()之前执行?如果JUnit根本没有这个特性,为什么它的设计者不设计者个特性?
如果一定要在JUnit4里面设定执行顺序,有什么办法?(请不要强调解释为啥要测试独立)
If you really need hard dependency between your JUnit test, try JExample extensionJExample introduces producer-consumer relationships to unit-testing.
A producer is a test method that yields its unit under test as return value.
A consumer is a test method that depends on one or more producers and their return values.You can install it in Eclipse, for Junit4.4 or 4.5.import jexample.Depends; @Test
@Depends("#testEmpty")
public Stack<Integer> testPush(Stack<Integer> $) {
$.push(42);
assertFalse($.isEmpty());
return $;
}