Spring Boot中進行Junit測試

2022-01-21 18:57:47 字數 1818 閱讀 6079

spring boot新版本預設使用junit5,pom依賴為:

<

dependency

>

<

groupid

>org.springframework.boot

groupid

>

<

artifactid

>spring-boot-starter-test

artifactid

>

<

scope

>test

scope

>

<

exclusions

>

<

exclusion

>

<

groupid

>org.junit.vintage

groupid

>

<

artifactid

>junit-vintage-engine

artifactid

>

exclusion

>

exclusions

>

dependency

>

同時,測試類的demo如下,其中@springboottest表示將該類作為spring的測試類,載入到spring容器中,必不可少。

import

static

org.junit.jupiter.api.assertions.assertequals;

import

example.util.calculator;

import

org.junit.jupiter.api.test;

import org.springframework.boot.test.context.springboottest;

@springboottest

class

myfirstjunitjupitertests

}

如果專案中要使用舊版的junit4,那麼在pom檔案中要刪除掉「」這個對舊版本的支援,同時匯入junit4的相關依賴

<

dependency

>

<

groupid

>org.springframework.boot

groupid

>

<

artifactid

>spring-boot-starter-test

artifactid

>

<

scope

>test

scope

>

dependency

>

<

dependency

>

<

groupid

>junit

groupid

>

<

artifactid

>junit

artifactid

>

<

version

>4.12

version

>

<

scope

>test

scope

>

dependency

>

在測試類中,不要忘了新增@runwith(springrunner.class)註解,有時候@test的匯入的包也有影響,需要注意

文件:spring boot:

junit5:

SpringBoot中進行「方面」程式設計。

目錄 1 pom檔案,需要新增web和aop的boot依賴。2 定義controller和service。3 編寫切面類 4 執行boot專案 org.springframework.boot spring boot starter web org.springframework.boot spri...

Makefile中進行巨集定義

實際上是gcc命令支援 d巨集定義,相當於c中的全域性 define gcc d name gcc d name definition makefile中可以定義變數 和巨集很像 但是是給make直譯器用的,對所編譯的檔案完全沒有作用。mstar 巨集定義方式 字串定義方式和值定義方式 cc tvo...

在VBA中進行除錯

只要從您的專案中觸發 vba就會執行。從簡單的開啟表單到單擊命令按鈕,各種各樣的物件事件都可能引起這種情況。當某些事情無法按預期工作時,您如何才能準確確定出什麼問題以及在 好吧,這就是本文可以為您提供的幫助。對於每個office應用程式,當然包括access,都有乙個整合的偵錯程式。要開啟偵錯程式視...