Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/391.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何在junit测试中正确使用java流形库中的越狱?_Java_Unit Testing_Gradle_Junit - Fatal编程技术网

如何在junit测试中正确使用java流形库中的越狱?

如何在junit测试中正确使用java流形库中的越狱?,java,unit-testing,gradle,junit,Java,Unit Testing,Gradle,Junit,我正在使用java的扩展库进行junit测试,即使完全按照他们的方法进行测试,我也不知道我做错了什么 //我的类 包装实践; 公共类 { 公共类() { } 私有字符串get_String() { 返回“ABCDE”; } } //我的单元测试课——第一条路 包装实践; 导入manifold.ext.api.Jailbreak; 导入静态org.junit.Assert.assertEquals; 导入org.junit.Test; 公共类测试 { 公共类测试() { } @试验 public

我正在使用java的扩展库进行junit测试,即使完全按照他们的方法进行测试,我也不知道我做错了什么

//我的类
包装实践;
公共类
{
公共类()
{
}
私有字符串get_String()
{
返回“ABCDE”;
}
}
//我的单元测试课——第一条路
包装实践;
导入manifold.ext.api.Jailbreak;
导入静态org.junit.Assert.assertEquals;
导入org.junit.Test;
公共类测试
{
公共类测试()
{
}
@试验
public void assert_equals_true_test()
{
@越狱SomeClass sc=新SomeClass();
assertEquals(“Error equals”,“ABCDE”,sc.get_string());
}
}
//我的单元测试课——第二种方式
包装实践;
导入manifold.ext.api.Jailbreak;
导入静态org.junit.Assert.assertEquals;
导入org.junit.Test;
公共类测试
{
公共类测试()
{
}
@试验
public void assert_equals_true_test()
{
SomeClass sc=新的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和manifold扩展依赖项作为编译组:'systems.manifold',名称:'manifold ext',版本:'2019.1.12',您使用的是哪个版本的Java?如果是Java 9或更高版本,您是否使用JPMS(模块)?如果你发布你的Gradle脚本,我可以帮你正确设置。更好的方法是链接到您的项目。可能是没有显式设置--module路径,这是使用Java9+的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()
    }
}

流形项目倾向于在任何地方使用Maven;Gradle设置文档没有那么完美。

你的建议奏效了,唯一的区别是,我在
compileTestJava
任务中添加了
options.compileArgs+=['-Xplugin:Manifold']
,然后构建了它successfully@Scott那么Java8的设置呢?我找不到关于java 8的基本设置的有用文档gradle@AhmedSaid中的“生成”部分下有安装信息。如果你还有问题,请告诉我。干杯