spring_reference/VII. Spring Boot CLI/55.2. Testing your code.md

767 B
Raw Permalink Blame History

55.2. 测试你的代码

test命令允许你编译和运行应用程序的测试用例。常规使用方式如下:

$ spring test app.groovy tests.groovy
Total: 1, Success: 1, : Failures: 0
Passed? true

在这个示例中,test.groovy包含JUnit @Test方法或Spock Specification类。所有的普通框架注解和静态方法在不使用import导入的情况下仍旧可以使用。

下面是我们使用的test.groovy文件含有一个JUnit测试

class ApplicationTests {

    @Test
    void homeSaysHello() {
        assertEquals("Hello World!", new WebApplication().home())
    }

}

如果有多个测试源文件你可以倾向于使用一个test目录来组织它们。