找不到Junit方法

编程入门 行业动态 更新时间:2024-10-27 18:31:07
本文介绍了找不到Junit方法的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我正在尝试使用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 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方法

本文发布于:2023-11-14 05:01:33,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1586290.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:找不到   方法   Junit

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!