我正在使用java的manifold扩展库进行junit测试,即使在严格遵循了它们的docs之后,我也不知道我做错了什么。
// My Class
package practice_junit;
public class SomeClass
{
public SomeClass()
{
}
private String get_string()
{
return "ABCDE";
}
}
// My Unit Test Class -- first way
package practice_junit;
import manifold.ext.api.Jailbreak;
import static org.junit.Assert.assertEquals;
import org.junit.Test;
public class SomeClassTest
{
public SomeClassTest()
{
}
@Test
public void assert_equals_true_test()
{
@Jailbreak SomeClass sc = new SomeClass();
assertEquals("Error equals","ABCDE",sc.get_string());
}
}
// My Unit Test Class -- second way
package practice_junit;
import manifold.ext.api.Jailbreak;
import static org.junit.Assert.assertEquals;
import org.junit.Test;
public class SomeClassTest
{
public SomeClassTest()
{
}
@Test
public void assert_equals_true_test()
{
SomeClass sc = new SomeClass();
assertEquals("Error equals","ABCDE",sc.jailbreak().get_string());
}
}在这两种情况下,我都得到了相同的错误日志:
PS C:\Users\> gradle build
> Task :compileTestJava FAILED
C:\Users\SomeClassTest.java:19: error: get_string() has private access in SomeClass
assertEquals("Error equals","ABCDE",sc.get_string());
^
1 error
FAILURE: Build failed with an exception.
* What went wrong:
Execution failed for task ':compileTestJava'.
> Compilation failed; see the compiler error output for details.
* Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output. Run with --scan to get full insights.
* Get more help at https://help.gradle.org
BUILD FAILED in 1m 9s
3 actionable tasks: 1 executed, 2 up-to-date我使用gradle和流形扩展依赖项作为https://mvnrepository.com/artifact/systems.manifold/manifold-ext/2019.1.12中的compile group: 'systems.manifold', name: 'manifold-ext', version: '2019.1.12'
发布于 2019-08-27 10:11:40
您使用的是什么版本的Java?如果是Java 9或更高版本,您是否在使用JPMS (模块)?如果你发布你的Gradle脚本,我可以帮助你正确地设置它。更好的方法是,使用指向您项目的链接的post an issue on the manifold github。可能没有显式设置-- 9+ -path,这是使用Java的Gradle脚本中非常常见的问题。以下是相关的部分:
dependencies {
compile group: 'systems.manifold', name: 'manifold-ext', version: '2019.1.12'
testCompile group: 'junit', name: 'junit', version: '4.12'
// Add manifold to -processorpath for javac (for Java 9+)
annotationProcessor group: 'systems.manifold', name: 'manifold-ext', version: '2019.1.12'
}
compileJava {
doFirst() {
// If you DO NOT define a module-info.java file:
options.compilerArgs += ['-Xplugin:Manifold']
// if you DO define a module-info.java file:
//options.compilerArgs += ['-Xplugin:Manifold', '--module-path', classpath.asPath]
//classpath = files()
}
}Manifold项目倾向于在任何地方都使用Maven;Gradle设置文档没有那么精致。
https://stackoverflow.com/questions/57656810
复制相似问题