【发布时间】:2014-05-20 07:14:12
【问题描述】:
**Description**
Access restriction: The type Test is not accessible due to restriction on required library
**Resource**
/Applications/Eclipse Java/plugins/org.junit_4.11.0.v201303080030/junit.jar
**Path**
AdditionTest2.java
**Location**
/Practice/src/testing line 5
**Type**
Java Problem
我已经看到了这些其他 SO 线程的答案:
Access restriction on class due to restriction on required library
Access restriction on class due to restriction on required library rt.jar?
并且我已经应用了修复 - 构建路径 -> 删除系统库 -> 重新添加它,它可以工作。但是,我还有两个问题:
1.为什么代码仍然以红色突出显示?
顺便说一句,代码如下
package testing;
import static org.junit.Assert.*;
import org.junit.Test;
public class AdditionTest2 {
// @Test is underlined red
@Test
public void testAddition() {
Addition add = new Addition();
int[] numbers = {1, 2};
// this line is underlined red
assertEquals("1 + 2 must be 3", 3, Addition.add(numbers));
}
}
2.是什么导致了这个错误?同样,我已经阅读了这两个主题,但我仍然不明白。
谢谢!
巴乔
编辑:实际上,我的立场是正确的——它不起作用。我对 eclipse 中的测试不太熟悉,但是在 JUnit 选项卡下,什么也没有发生。
编辑 2:构建路径图像(如果有帮助)
EDIT 3:为 JUnit 3 和 JUnit 4 构建路径映像
EDIT 4 + 解决方案:实际上,使用 JUnit 4 的测试代码根本没有运行 - 当我单击 Run --> Run As it didn't run - 我试图删除 JUnit 3来自构建路径,它现在可以工作了!除了现在我还有另一个问题是不知道为什么测试失败,但这是另一个问题。
【问题讨论】:
-
JUnit 的构建路径条目是什么样的?查看
.classpath并将该行附加到您的问题中。 -
您在“控制台”视图中看到了什么吗?
-
@AaronDigulla 抱歉,我对构建路径等不太熟悉 - 你的意思是项目 --> 属性 --> Java 构建路径吗?如果是这样,我已经在上面发布了。抱歉,我使用的是 Mac,如何显示 .classpath?
-
@blazonix:关闭 :-) 我们对“JUnit 3”下的内容更感兴趣。