Java JUnit 测试,无根测试:初始化错误

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/23229538/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-13 21:26:23  来源:igfitidea点击:

JUnit test, Unrooted Tests: initializationError

javaunit-testingmavenjunit

提问by Richard

So I edited the name of a JUnit test and now it wont work. Instead I get Unrooted Tests: initializationError.

所以我编辑了一个 JUnit 测试的名称,现在它不起作用了。相反,我得到了无根测试:初始化错误。

This is a simple test. Infact it is a test for JUnit tests as I am just starting to use it.

这是一个简单的测试。事实上,它是对 JUnit 测试的测试,因为我刚刚开始使用它。

@Test
public void testRun()
    String s = null;
    assertNull(s);

}

and all i did was change it to testRun2(). Also when I run the file not the individual test, it still runs the old testRun(), not testRun2().

我所做的只是将其更改为 testRun2()。此外,当我运行文件而不是单个测试时,它仍然运行旧的 testRun(),而不是 testRun2()。

My project has Maven not sure if that is a factor. And I have updated the project

我的项目让 Maven 不确定这是否是一个因素。我已经更新了项目

回答by Richard

So it turned out that I needed to rebuild using Maven to update the classes. Now it works fine and I can add/modify test cases.

所以结果我需要使用 Maven 重建来更新类。现在它工作正常,我可以添加/修改测试用例。

回答by raja777m

In my case, i changed the method name and it didn't update it automatically, so the above solution of Project> Clean worked well for me.

就我而言,我更改了方法名称并且它没有自动更新它,因此上面的 Project> Clean 解决方案对我来说效果很好。

回答by FF0000

Another way this error would occur is forgetting the Test annotation. Encountered when right click method name in Eclipse and Run As -> Junit Test.

发生此错误的另一种方式是忘记 Test 注释。在 Eclipse 中右键单击方法名称并运行为 -> Junit 测试时遇到。