javajunit测试问题

javajunit测试问题,java,unit-testing,junit,testcase,Java,Unit Testing,Junit,Testcase,我正在使用JUnit4。我的整个计划运作良好。我正在尝试编写一个测试用例。但是有一个错误 这里是非常基本的样本测试 public class di extends TestCase{ private static Records testRec; public void testAbc() { Assert.assertTrue( "There should be some thing.", di.testRec.

我正在使用JUnit4。我的整个计划运作良好。我正在尝试编写一个测试用例。但是有一个错误

这里是非常基本的样本测试

public class di  extends TestCase{
    private static Records testRec;
    public void testAbc() {
        Assert.assertTrue(
            "There should be some thing.",
            di.testRec.getEmployee() > 0);
    }

}
当我运行这个时,它会给我一个错误

fName can not be null
如果我用super这样做

public TestA() {
super("testAbc");
}
一切正常。JUnit3.X以前不是这样的 我做错了还是他们改变了:( 对不起,我不清楚


在JUnit 4中,您不需要扩展
TestCase
,而是使用
@test
注释来标记您的测试方法:

public class MyTest {
    private static Records testRec;
    @Test
    public void testAbc() {
        Assert.assertTrue(
            "There should be some thing.",
            MyTest.testRec.getEmployee() > 0);
    }
}

作为旁注,在类中测试
静态
成员可能会使单元测试相互依赖,这不是一件好事。除非您有很好的理由,否则我建议删除
静态
限定符。

这不是您的情况,但此错误也可能意味着您有一个名为
测试的文件。项目中的java
。重命名它将修复错误,但重构后
@Test
将更改为
@NewName
(至少在Eclipse中)因此,请记住手动将其更改回
@Test

什么是TestAgnes?第一个代码段中没有提到它。请清除您的问题。感谢您的回答。当我尝试此操作时,它给了我错误“类型不匹配:无法从测试转换为注释”我应该如何避免此错误?如果我使用@Test听起来像您导入了其他一些不是注释的测试类,它会告诉我。请确保导入
org.junit.Test
,这将解决此问题。如果您遇到“类型不匹配”,我想补充一点上面的错误,您可能正在执行我所做的操作,并将您的测试类命名为“test”,这与导入冲突。