java - JMockit 在单元测试中保持不变

标签 java unit-testing junit jmockit

我使用 JUnit 进行单元测试。我使用 JMockit 在单元测试中模拟一些 java.util 类:

   new MockUp<PrintWriter>() { //HERE UNIT TESTS HANG ON
        @SuppressWarnings("unused")
        @Mock(invocations = 5)
        public void print(String s) {
            System.out.print(s);
        }

        @SuppressWarnings("unused")
        @Mock(invocations = 1)
        public void flush() {}
    };

问题:我的单元测试只是停留在模型定义上。

问题:您能猜出问题所在吗?

我的依赖项:

<dependencies>
    <dependency>
        <groupId>junit</groupId>
        <artifactId>junit</artifactId>
        <version>4.11</version>
    </dependency>
    <dependency>
        <groupId>com.googlecode.jmockit</groupId>
        <artifactId>jmockit</artifactId>
        <version>1.7</version>
    </dependency>
</dependencies>

最佳答案

请查看此页面:

http://jmockit.googlecode.com/svn-history/r1123/trunk/www/installation.html

在第 4 步。

您可能缺少 jmockit 代理作为默认 VM 参数:

-javaagent:<path_to>\jmockit.jar

关于java - JMockit 在单元测试中保持不变,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23442467/

相关文章:

java - 在@Before 之外使用@InjectMocks

java - java中如何检查数组中的元素是否存在?

java - 将变量从一个类传递到 paintComponent 类

java - Junit 在我的测试用例中断言 OR 条件

angular - ng2-translate:无法读取 TranslatePipe.transform 处未定义的属性 'subscribe'

python - 如何在套件的测试类中共享一个 webdriver 实例?我使用 Selenium2 和 Python

java - 用于谷歌搜索的 google java api

java - SonarLint eclipse : Does it also analyze source code in "src/test"?

android-studio - 在单元测试中处理 protobuf 类时出现 NoSuchMethod 错误

java - 使用 Eclipse 创建新的 JUnit 测试用例