java assertTrue 语句需要在intelliJ IDEA 中静态导入?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/16213910/
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
assertTrue statement requires static import in intelliJ IDEA?
提问by coure2011
I just shifted my project form Netbeans to intelliJ IDEA, its a junit based test project. In netbeans I was using statments
我刚刚将我的项目从 Netbeans 转移到了 intelliJ IDEA,它是一个基于 junit 的测试项目。在 netbeans 中,我使用了 statments
assertTrue("Message", conditionCustom());
and it was working without any extra import. Now when using the same above command in intelliJ I have to import file
它在没有任何额外导入的情况下工作。现在在 intelliJ 中使用上述相同的命令时,我必须导入文件
import static org.junit.Assert.assertTrue;
is there any way so I dont need to write the above line in my code file? otherwise I have to edit all my files to get working assertTrue statement.
有什么办法让我不需要在我的代码文件中写上一行吗?否则我必须编辑我的所有文件才能使用 assertTrue 语句。
回答by duffymo
You either have to add the static import OR make clear what class that static call is associated with:
您要么必须添加静态导入,要么明确静态调用与哪个类相关联:
Assert.assertTrue("Message", conditionCustom());
I usually use the latter because I think it's clearer.
我通常使用后者,因为我认为它更清晰。
Java won't compile unless it can figure out which class to associate that static method with.
Java 不会编译,除非它能够找出与该静态方法关联的类。
I'd guess that perhaps you use inheritance to associate that static method with your test.
我猜想也许您使用继承将该静态方法与您的测试相关联。