为什么org.junit.Assert.assertTrue要静态导入

转自:http://stackoverflow.com/questions/16213910/asserttrue-statement-requires-static-import-in-intellij-idea


提问:

I just shifted my project form Netbeans to intelliJ IDEA, its a junit based test project. In netbeans I was using 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

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.


回答:

You either have to add the static import OR make clear what class that static call is associated with:

Assert.assertTrue("Message", false);

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.

I'd guess that perhaps you use inheritance to associate that static method with your test.


你可能感兴趣的:(为什么org.junit.Assert.assertTrue要静态导入)