jmockit搭配testng与junit的对比

jmockit搭配testng与junit的对比

maven依赖

<dependencies>
    <dependency>
        <groupId>org.jmockit</groupId>
        <artifactId>jmockit</artifactId>
        <version>1.36</version>
    </dependency>
    <dependency>
        <groupId>org.testng</groupId>
        <artifactId>testng</artifactId>
        <version>7.1.0</version>
    </dependency>
    <dependency>
        <groupId>junit</groupId>
        <artifactId>junit</artifactId>
        <version>4.12</version>
    </dependency>
</dependencies>

java代码

import mockit.Mocked;
import java.util.Locale;

public class LocaleTest {

    @org.testng.annotations.Test
    public void test1(@Mocked Locale locale) {
        System.out.println(locale);//null
    }

    @org.junit.Test
    public void test2(@Mocked Locale locale) {
        System.out.println(locale);//java.util.Locale@224aed64
    }
}

结论

当使用jmockit+testng做单元测试时,传入测试方法的@Mocked参数为空;当使用jmockit+junit做单元测试时,传入测试方法的@Mocked参数不为空。

posted @ 2021-11-25 01:25  夏恒  阅读(94)  评论(0编辑  收藏  举报