找不到Junit方法 [英] Junit method not found
问题描述
我正在尝试使用junit框架构建一个示例测试类。
我已经下载了junit4.9b3。
当我尝试编译我的测试类时,我得到了以下错误: -
I'm trying to build a sample test class using junit framework.
I've downloaded junit4.9b3.
When I try to complie my test class I get the following error:-
javac -cp ".;C:\Documents and Settings\user\Desktop\junit\junit4.9b3\junit-4.9b3.jar"
TestSubscription.java
TestSubscription.java:10: cannot find symbol
symbol : method assertTrue(boolean)
location: class TestSubscription
assertTrue(s.pricePerMonth()==100.0);
^
TestSubscription.java:17: cannot find symbol
symbol : method assertTrue(boolean)
location: class TestSubscription
assertTrue(s.pricePerMonth()==66.67);
^
2 errors
看起来assertTrue不可用但junit javadoc提到这个方法。
我使用导入如下
Looks like assertTrue is not available but the junit javadoc mentions this method.
I'm using the import as follows
import org.junit.*;
import org.junit.Assert.*;
任何想法?
推荐答案
您已导入类型,但未使用 静态导入,使成员无需资格即可使用。如果你使用:
You've imported the types, but not used a static import to make the members available without qualification. If you use:
import static org.junit.Assert.*;
那么应该静态导入 Assert $中的所有静态方法c $ c> class,所以你可以写
assertTrue
而不是 Assert.assertTrue
。
then that should statically import all the static methods in the Assert
class, so you can write assertTrue
instead of Assert.assertTrue
.
请注意,大概 Assert
本身有嵌套类型,否则我预计你的正常导入会失败。
Note that presumably Assert
itself has nested types, otherwise I'd have expected your "normal" import to fail.
这篇关于找不到Junit方法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!