网站建设是广告吗,卖货平台有什么软件呢,公司想做个自己的网站怎么做的,建站之星破解版下载spring-junit4这是关于将基于Gradle的Spring Boot应用程序从Junit 4迁移到闪亮的新Junit 5的快速文章。Junit 4测试继续与Junit 5 Test Engine抽象一起工作#xff0c;该抽象为在不同编程模型中编写的测试提供支持。例如#xff0c;Junit 5支持能够运行JUnit 4测试的Vintage … spring-junit4 这是关于将基于Gradle的Spring Boot应用程序从Junit 4迁移到闪亮的新Junit 5的快速文章。Junit 4测试继续与Junit 5 Test Engine抽象一起工作该抽象为在不同编程模型中编写的测试提供支持。例如Junit 5支持能够运行JUnit 4测试的Vintage Test Engine。 这是一个具有JUnit 5集成的示例项目 以及在Junit 4和Junit 5中的示例测试– https://github.com/bijukunjummen/boot2-with-junit5-sample 样本Junit 4候选测试 作为一个候选项目我有一个Spring Boot 2应用程序该应用程序使用Junit 4作为测试框架使用Kotlin编写了测试。 这是在显式调出所有依赖项的情况下样本测试的外观。 它使用Junit4的RunWith注释加载Spring Context import org.assertj.core.api.Assertions.assertThat
import org.junit.Test
import org.junit.runner.RunWith
import org.springframework.beans.factory.annotation.Autowired
import org.springframework.boot.test.autoconfigure.web.reactive.WebFluxTest
import org.springframework.test.context.junit4.SpringRunner
import org.springframework.test.web.reactive.server.WebTestClient
import java.nio.charset.StandardCharsetsRunWith(SpringRunner::class)
WebFluxTest(controllers arrayOf(RouteConfig::class))
class SampleJunit4Test {Autowiredlateinit var webTestClient: WebTestClientTestfun get of hello URI should return Hello World!() {webTestClient.get().uri(/hello).exchange().expectStatus().isOk.expectBody().consumeWith({ m -assertThat(String(m.responseBodyContent, StandardCharsets.UTF_8)).isEqualTo(Hello World!)})}} Junit 4依赖项通过“ spring-boot-starter-test”模块可传递地引入 testCompile(org.springframework.boot:spring-boot-starter-test)Junit 5迁移 第一步是引入Junit 5依赖项以及Gradle插件该插件可以运行测试 插入 buildscript {dependencies {....classpath org.junit.platform:junit-platform-gradle-plugin:1.0.2}
}
apply plugin: org.junit.platform.gradle.plugin 依存关系 testCompile(org.junit.jupiter:junit-jupiter-api)
testRuntime(org.junit.jupiter:junit-jupiter-engine)
testRuntime(org.junit.vintage:junit-vintage-engine:4.12.2) 完成这些更改后所有Junit 4测试都将继续在IDE中以及在执行Gradle构建时运行此时测试本身可以缓慢迁移。 我之前显示的测试与Junit 5 Jupiter相似它提供了测试的编程模型 import org.junit.jupiter.api.Assertions.assertEquals
import org.junit.jupiter.api.Test
import org.junit.jupiter.api.extension.ExtendWith
import org.springframework.beans.factory.annotation.Autowired
import org.springframework.boot.test.autoconfigure.web.reactive.WebFluxTest
import org.springframework.test.context.junit.jupiter.SpringExtension
import org.springframework.test.web.reactive.server.WebTestClient
import java.nio.charset.StandardCharsetsExtendWith(SpringExtension::class)
WebFluxTest(controllers arrayOf(RouteConfig::class))
class SampleJunit5Test {Autowiredlateinit var webTestClient: WebTestClientTestfun get of hello URI should return Hello World!() {webTestClient.get().uri(/hello).exchange().expectStatus().isOk.expectBody().consumeWith({ m -assertEquals(Hello World!, String(m.responseBodyContent, StandardCharsets.UTF_8))})}} 需要注意的是现在而不是使用JUnit 4 RunWith注释我现在用的是ExtendWith标注并提供SpringExtension作为一个参数它负责加载了Spring上下文像以前一样。 Spring注释的其余部分将继续与JUnit 5一起使用。通过这种方式可以将测试从JUnit 4缓慢移至JUnit 5。 注意事项 但是并非一切都十分顺利从JUnit 4迁移到JUnit 5时会遇到一些问题其中最大的问题可能是对JUnit Rule和ClassRule批注的支持并且JUnit 5文档确实详细介绍了如何实现。减轻了 。 翻译自: https://www.javacodegeeks.com/2018/01/spring-based-application-migrating-junit-5.htmlspring-junit4