在下面的测试类中,我的测试对象没有被初始化,因为Before没有被调用。为什么不在@Before被调用
任何想法?
import junit.framework.TestCase;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
public class CalcDateToolTest extends TestCase
{
DatesCalculator calc;
@Before
public void initialize() {
System.out.println("Before");
calc = new DatesCalculator("15/06/2013", "30/06/2013");
}
@Test
public void testCalcDayDiff() {
assertEquals(true, calc.getFromDate());
}
@After
public void destroy() {
calc = null;
}
}
你为什么要删除旧的帖子?我当时正确地发表了对相关问题的评论......可能有一个答案:http://stackoverflow.com/a/733358/1993402。结论是:'不要同时扩展TestCase和使用注释!' – ConcurrentHashMap 2014-09-13 09:54:40
可能的重复[为什么不是我的@BeforeClass方法正在运行?](http://stackoverflow.com/questions/733037/why- isnt-my-before-class-method-running) – Joe 2014-09-13 10:43:31