简体   繁体   English

assertTrue语句需要在intelliJ IDEA中进行静态导入吗?

[英]assertTrue statement requires static import in intelliJ IDEA?

I just shifted my project form Netbeans to intelliJ IDEA, its a junit based test project. 我刚刚将我的项目从Netbeans转移到了IntelliJ IDEA,这是一个基于junit的测试项目。 In netbeans I was using statments 在netbeans我使用的是法令

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语句。

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. 我想也许你可以使用继承将静态方法与测试相关联。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM