diff --git a/VII. Spring Boot CLI/55.2. Testing your code.md b/VII. Spring Boot CLI/55.2. Testing your code.md index e69de29..0e84ae4 100644 --- a/VII. Spring Boot CLI/55.2. Testing your code.md +++ b/VII. Spring Boot CLI/55.2. Testing your code.md @@ -0,0 +1,22 @@ +### 55.2. 测试你的代码 + +`test`命令允许你编译和运行应用程序的测试用例。常规使用方式如下: +```shell +$ spring test app.groovy tests.groovy +Total: 1, Success: 1, : Failures: 0 +Passed? true +``` +在这个示例中,`test.groovy`包含JUnit `@Test`方法或Spock `Specification`类。所有的普通框架注解和静态方法在不使用import导入的情况下,仍旧可以使用。 + +下面是我们使用的`test.groovy`文件(含有一个JUnit测试): +```java +class ApplicationTests { + + @Test + void homeSaysHello() { + assertEquals("Hello World!", new WebApplication().home()) + } + +} +``` +**注**:如果有多个测试源文件,你可以倾向于使用一个test目录来组织它们。