首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >如何正确使用java流形库中的Jailbreak进行junit测试?

如何正确使用java流形库中的Jailbreak进行junit测试?
EN

Stack Overflow用户
提问于 2019-08-26 19:12:50
回答 1查看 1.9K关注 0票数 2

我正在使用java的manifold扩展库进行junit测试,即使在严格遵循了它们的docs之后,我也不知道我做错了什么。

代码语言:javascript
复制
// 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());
    }
}

在这两种情况下,我都得到了相同的错误日志:

代码语言:javascript
复制
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'

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2019-08-27 10:11:40

您使用的是什么版本的Java?如果是Java 9或更高版本,您是否在使用JPMS (模块)?如果你发布你的Gradle脚本,我可以帮助你正确地设置它。更好的方法是,使用指向您项目的链接的post an issue on the manifold github。可能没有显式设置-- 9+ -path,这是使用Java的Gradle脚本中非常常见的问题。以下是相关的部分:

代码语言:javascript
复制
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设置文档没有那么精致。

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/57656810

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档