其他分享
首页 > 其他分享> > jmockit搭配testng与junit的对比

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参数不为空。

标签:jmockit,Mocked,locale,testng,org,junit
来源: https://www.cnblogs.com/henx/p/15601044.html