在本章中,我们将测试在 Hello World示例章节中创建的示例项目,以演示Spring CLI的测试功能.按照下表中列出的步骤测试示例项目 :
Sr.否 | Step&描述 |
---|---|
1 | 创建 FirstApplication. Test 文件夹中的groovy 和 TestFirstApplication.groovy ,如下所述. |
2 | 编译并运行应用程序以验证实现逻辑的结果. |
@RestController class FirstApplication { @RequestMapping("/") String welcome() { "Welcome to TutorialsPoint.Com" } }
class TestFirstApplication { @Test void welcomeTest() { assertEquals("Welcome to TutorialsPoint.Com", new FirstApplication().welcome()) } }
到ru在应用程序中,键入以下命令 :
E:/Test/FirstApplication/> spring test FirstApplication.groovy TestFirstApplication.groovy
现在Spring Boot CLI将开始运行,下载所需的依赖项,编译源代码和测试文件并进行单元测试码.将在控制台上生成以下输出 :
Resolving dependencies........................................................ . Time: 0.457 OK (1 test)
请考虑以下几点以了解Spring CLI采取的操作 :
@Test注释指示CLI下载JUnit 4.12版本.
Spring CLI使用其元数据自动检测版本,因为我们没有指定任何依赖.
最后,在代码编译之后,测试应用程序.