繁体   English   中英

导入无法解析(Junit)

[英]Import cannot be resolved (Junit)

我正在尝试使用Windows上的Eclipse IDE在Maven为我的项目编写单元测试。

我已经使用Eclipse插件在构建路径上导入了jUnit4

(junit.jar under /path/to/eclipse/plugins/org.junit4.12.0.v201504281640). 

我能够导入这些。 (古怪)

import org.junit.Test;
import org.junit.runner.RunWith;

但是我导入这些有问题

import static org.junit.Assert.assertEquals;
import org.junit.Before;

我是否必须添加另一个JUnit库,还是有其他问题?

注意: Maven中没有JUnit依赖项。 我直接在构建路径中导入JUnit jar。

编辑:我忘了提,但我确实对junit.Assert使用static。

assertEquals不是类而是方法,因此您必须选择:

导入org.junit.Assert;

并调用Assert.assertEquals

或使用:

导入静态org.junit.Assert.assertEquals;

并调用:assertEquals

暂无
暂无

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

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