Junit的最简单样例:Hello world!

我的技术博客经常被流氓网站恶意爬取转载。请移步原文:http://www.cnblogs.com/hamhog/p/3824934.html,享受整齐的排版、有效的链接、正确的代码缩进、更好的阅读体验。

不多说了,贴两段代码。

HelloWorld类:

public class HelloWorld {
    
    public void main() {
        System.out.println(helloWorld());
    }
    
    public static String helloWorld() {
        return "Hello World!";
    }

}

TestHelloWord

import static org.junit.Assert;
import org.junit.Test;

public class TestHelloWorld {
    
    @Test public void helloWorldNormal() {
        String result = HelloWorld.helloWorld();
        Assert.assertEquals("Hello World!", result);
    }

}

这就是一个简单的单元测试啦。没有想象的复杂吧:)

原文地址:https://www.cnblogs.com/hamhog/p/3830373.html