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

23 lines
767 B
Markdown
Raw Normal View History

2015-03-09 15:28:33 +00:00
### 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目录来组织它们。