Spring boot快速入门
- Spring Boot war包启动
- 什么是Spring boot
- 快速了解Spring Boot
- Spring boot入门实例
- springboot 整合freemarker
- Spring Boot使用FastJson解析JSON数据
- Spring Boot上传文件示例
Spring Boot CLI教程
开源项目
知识点
相关文章
更多最近更新
更多Spring Boot CLI单元测试
2019-04-29 23:20|来源: 网路
这里将测试在Hello World示例章节中创建的示例项目,以演示Spring CLI的测试功能。 按照下面提到的步骤测试示例项目 -
第1步
在Test
文件夹中创建FirstApplication.groovy
和TestFirstApplication.groovy
,如下所述。
第2步
编译并运行应用程序以验证实现的逻辑的结果。
文件: FirstApplication/FirstApplication.groovy -
@RestController class FirstApplication { @RequestMapping("/") String welcome() { "Welcome to 656463.Com" } }
文件: FirstApplication/TestFirstApplication.groovy -
class TestFirstApplication { @Test void welcomeTest() { assertEquals("Welcome to 656463.Com", new FirstApplication().welcome()) } }
运行该应用程序
输入以下命令 -
D:\worksp\springboot-cli/> spring test FirstApplication.groovy TestFirstApplication.groovy
现在,Spring Boot CLI将开始运行,下载所需的依赖项,编译源代码和测试文件以及单元测试代码。可以在控制台上看到以下输出 -
Resolving dependencies........................................................ . Time: 0.457 OK (1 test) 111
执行顺序和要点
以下操作由Spring CLI执行 -
@Test
注释指示CLI下载JUnit 4.12
版本。Spring CLI
使用其元数据自动检测版本,因为没有指定任何依赖项。最后,它编译代码,测试应用程序
相关问答
更多-
是不是有一款什么手机软件,可以很自然的拉长腿部?不是美图秀秀,有知道的不?[2022-10-20]
spring -
那说明单元测试里面没有包含servercontainer吧,单元测试加载的东西没有项目正规启动以后那么多,需要仔细检查如何在单元测试中加载servercontainer。
-
春天的英语怎么读?[2022-05-21]
spring -
那说明单元测试里面没有包含servercontainer吧,单元测试加载的东西没有项目正规启动以后那么多,需要仔细检查如何在单元测试中加载servercontainer。
-
测试自动配置: 我们来创建一个非常简单的示例来测试我们的自动配置。 我们将创建一个名为MyUser的实体类,以及一个使用Spring Data的MyUserRepository接口: @Entity public class MyUser { @Id private String email; // standard constructor, getters, setters } public interface MyUserRepository extends JpaRe ...
-
您应该使用Sprint测试上下文框架检查: http : //docs.spring.io/spring/docs/current/spring-framework-reference/html/testing.html#integration-testing-annotations 你可以在这里找到lib: https : //maven-repository.com/artifact/org.springframework/spring-test 您应该使用@ContextConfiguration注释 ...
-
代替: .sessionAttr("_csrf.parameterName", "_csrf") .sessionAttr("_csrf.token", csrfToken.getToken()) 尝试: .sessionAttr("_csrf", csrfToken) 当您编写${_csrf.parameterName} ,FreeMarker会在模型变量“_csrf”中查找字段“parameterName”。 不适用于模型变量“_csrf.parameterName”。 也就是说,你必须在测试中将这 ...
-
由于您正在加载配置类MyApplication.class因此将创建数据源bean,尝试在另一个未在测试中使用的bean中移动数据源,确保为测试加载的所有类都不依赖于数据源。 要么 在你的测试中创建一个标有@TestConfiguration的配置类,并将它包含在SpringBootTest(classes=TestConfig.class) , @TestConfiguration数据源就像那样 @Bean public DataSource dataSource() { return Mocki ...
-
嘲笑Spring Boot(Mocking Spring Boot)[2022-05-26]
在文章的底部有一个指向github repo的链接,其中包含测试的完整源代码。 在那里你可以看到以下行: import static org.mockito.BDDMockito.given; On the bottom of the article there is a link to the github repo with the full source of the test. There you can see the following line: import static org.mock ... -
如何仅为单元测试禁用球衣过滤器(使用spring-boot)(How to disable jersey filters for unit tests only (using spring-boot))[2022-06-06]
可能你最好的选择是使用Spring Profiles 。 您可以将帖子中的ResourceConfig标记为“生产”配置,而对于测试,可以创建具有“测试”配置文件的新ResourceConfig 。 然后在测试中将活动配置文件设置为"test" ,并在生产中将活动配置文件设置为"production" @Profile("production") @Configuration @ApplicationPath("/some/path") public class MyJerseyConfiguration ...