聊聊springboot2.2.3升級到2.4.0單元測試的區別

springboot2.2.3升級到2.4.0單元測試區別

原先單元測試 import org.junit.Test; 然後運行正常,現在運行報錯,

import org.junit.Test; 

換成

import org.junit.jupiter.api.Test; 

後運行正常。

單個單元測試的這樣沒有問題瞭,但是我批量執行的還是會報上面的錯誤

@Suite.SuiteClasses({
		//dao層測試類
	
		//service層測試類
		CheckConfigServiceTest.class,
		AfterCheckConfigServiceTest.class,
		
		//control層測試類
		//WebTestControllerTest.class		
		//util測試類		
	})
@RunWith(Suite.class)  
public class BatchTest {
}

最後確實沒有解決整合測試也稱 打包測試的@Suite.SuiteClasses方法,不過找到瞭別的批量執行單元測試的方法,

在src/test/java 文件夾右鍵,run as -> junit test 一樣可以批量執行!!!

springboot2.4降級到boot2.2.x

最近在做一個springcloud的整合項目,但是springcloud-alibaba的nacos隻支持2.2.x版本,而項目開始也沒註意,直接用的2.4版本,所以這裡記錄下降級踩下的坑。

這裡直接把boot版本號改成2.2.6然後去啟動主啟動類會出現

    <parent>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-parent</artifactId>
        <version>2.2.6.RELEASE</version>
        <relativePath/> <!-- lookup parent from repository -->
    </parent>

以下提示:我的spring和我的boot不兼容,我boot版本太低,讓我改成2.3或者是2.4

***************************
APPLICATION FAILED TO START
***************************

Description:

Your project setup is incompatible with our requirements due to following reasons:

– Spring Boot [2.2.6.RELEASE] is not compatible with this Spring Cloud release train

Action:

Consider applying the following actions:

– Change Spring Boot version to one of the following versions [2.3.x, 2.4.x] .
You can find the latest Spring Boot versions here [https://spring.io/projects/spring-boot#learn].
If you want to learn more about the Spring Cloud Release train compatibility, you can visit this page [https://spring.io/projects/spring-cloud#overview] and check the [Release Trains] section.
If you want to disable this check, just set the property [spring.cloud.compatibility-verifier.enabled=false]

Process finished with exit code 1

我這邊直接把springcloud版本一起降低改成H版本

  <properties>
        <java.version>1.8</java.version>
        <spring-cloud.version>Hoxton.SR9</spring-cloud.version>
    </properties>
    <dependencyManagement>
        <dependencies>
            <dependency>
                <groupId>org.springframework.cloud</groupId>
                <artifactId>spring-cloud-dependencies</artifactId>
                <version>${spring-cloud.version}</version>
                <type>pom</type>
                <scope>import</scope>
            </dependency>
        </dependencies>
    </dependencyManagement>

再次啟動,發現可以瞭,好瞭不多bb瞭,我要去改接下去其他模塊瞭

以上為個人經驗,希望能給大傢一個參考,也希望大傢多多支持WalkonNet。

推薦閱讀: