中文亚洲精品无码_熟女乱子伦免费_人人超碰人人爱国产_亚洲熟妇女综合网

當(dāng)前位置: 首頁 > news >正文

番禺做網(wǎng)站多少錢濟(jì)南頭條今日新聞

番禺做網(wǎng)站多少錢,濟(jì)南頭條今日新聞,谷歌優(yōu)化師,WordPress博客Vieu主題破解JUnit測試運(yùn)行器(Test Runner)決定了JUnit如何執(zhí)行測試。JUnit有多個(gè)測試運(yùn)行器,每個(gè)運(yùn)行器都有特定的功能和用途。 1. 默認(rèn)運(yùn)行器 當(dāng)沒有顯式指定運(yùn)行器時(shí),JUnit會(huì)使用默認(rèn)運(yùn)行器,這在JUnit 4和JUnit 5之間有所不同…

JUnit測試運(yùn)行器(Test Runner)決定了JUnit如何執(zhí)行測試。JUnit有多個(gè)測試運(yùn)行器,每個(gè)運(yùn)行器都有特定的功能和用途。

1. 默認(rèn)運(yùn)行器

當(dāng)沒有顯式指定運(yùn)行器時(shí),JUnit會(huì)使用默認(rèn)運(yùn)行器,這在JUnit 4和JUnit 5之間有所不同。

JUnit 4 默認(rèn)運(yùn)行器

在JUnit 4中,默認(rèn)運(yùn)行器是BlockJUnit4ClassRunner

import org.junit.Test;
import static org.junit.Assert.assertEquals;public class DefaultRunnerTest {@Testpublic void testAdd() {assertEquals(5, 2 + 3);}
}
JUnit 5 默認(rèn)運(yùn)行器

在JUnit 5中,不需要顯式指定運(yùn)行器,JUnit Jupiter會(huì)自動(dòng)運(yùn)行測試。

import org.junit.jupiter.api.Test;
import static org.junit.jupiter.api.Assertions.assertEquals;public class DefaultRunnerTest {@Testpublic void testAdd() {assertEquals(5, 2 + 3);}
}

2. @RunWith 注解

@RunWith注解用于指定JUnit 4的測試運(yùn)行器。以下是一些常用的運(yùn)行器:

2.1 SpringRunner

SpringRunner(原名SpringJUnit4ClassRunner)用于在JUnit 4中運(yùn)行Spring測試,提供Spring應(yīng)用程序上下文的支持。

import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.test.context.junit4.SpringRunner;
import static org.junit.Assert.assertEquals;@RunWith(SpringRunner.class)
public class SpringRunnerTest {@Testpublic void testAdd() {assertEquals(5, 2 + 3);}
}
2.2 Parameterized

Parameterized運(yùn)行器用于運(yùn)行參數(shù)化測試,即同一個(gè)測試方法可以用不同的參數(shù)多次運(yùn)行。

import org.junit.Test;
import org.junit.runner.RunWith;
import org.junit.runners.Parameterized;
import java.util.Arrays;
import java.util.Collection;
import static org.junit.Assert.assertEquals;@RunWith(Parameterized.class)
public class ParameterizedTest {private int input1;private int input2;private int expected;public ParameterizedTest(int input1, int input2, int expected) {this.input1 = input1;this.input2 = input2;this.expected = expected;}@Parameterized.Parameterspublic static Collection<Object[]> data() {return Arrays.asList(new Object[][] {{ 1, 2, 3 },{ 2, 3, 5 },{ 3, 5, 8 }});}@Testpublic void testAdd() {assertEquals(expected, input1 + input2);}
}
2.3 Suite

Suite運(yùn)行器用于運(yùn)行一組測試類。

import org.junit.runner.RunWith;
import org.junit.runners.Suite;@RunWith(Suite.class)
@Suite.SuiteClasses({TestClass1.class,TestClass2.class
})
public class TestSuite {// 空類,僅用于運(yùn)行指定的測試類
}

3. JUnit 5 擴(kuò)展模型

在JUnit 5中,不使用@RunWith,而是使用@ExtendWith注解來擴(kuò)展測試功能。

3.1 SpringExtension

SpringExtension用于在JUnit 5中運(yùn)行Spring測試,提供Spring應(yīng)用程序上下文的支持。

import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.ExtendWith;
import org.springframework.test.context.junit.jupiter.SpringExtension;
import static org.junit.jupiter.api.Assertions.assertEquals;@ExtendWith(SpringExtension.class)
public class SpringExtensionTest {@Testpublic void testAdd() {assertEquals(5, 2 + 3);}
}
3.2 ParameterizedTest

@ParameterizedTest注解用于運(yùn)行參數(shù)化測試,即同一個(gè)測試方法可以用不同的參數(shù)多次運(yùn)行。

import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.CsvSource;
import static org.junit.jupiter.api.Assertions.assertEquals;public class ParameterizedTestExample {@ParameterizedTest@CsvSource({"1, 2, 3","2, 3, 5","3, 5, 8"})void testAdd(int input1, int input2, int expected) {assertEquals(expected, input1 + input2);}
}

4. 自定義運(yùn)行器和擴(kuò)展

4.1 自定義JUnit 4 運(yùn)行器

可以創(chuàng)建自定義運(yùn)行器來擴(kuò)展JUnit 4的功能。

import org.junit.runners.BlockJUnit4ClassRunner;
import org.junit.runners.model.InitializationError;public class CustomRunner extends BlockJUnit4ClassRunner {public CustomRunner(Class<?> klass) throws InitializationError {super(klass);}@Overrideprotected void runChild(org.junit.runners.model.FrameworkMethod method, org.junit.runner.notification.RunNotifier notifier) {System.out.println("Running test: " + method.getName());super.runChild(method, notifier);}
}import org.junit.Test;
import org.junit.runner.RunWith;@RunWith(CustomRunner.class)
public class CustomRunnerTest {@Testpublic void testAdd() {assertEquals(5, 2 + 3);}
}
4.2 自定義JUnit 5 擴(kuò)展

可以創(chuàng)建自定義擴(kuò)展來擴(kuò)展JUnit 5的功能。

import org.junit.jupiter.api.extension.BeforeEachCallback;
import org.junit.jupiter.api.extension.ExtensionContext;public class CustomExtension implements BeforeEachCallback {@Overridepublic void beforeEach(ExtensionContext context) {System.out.println("Before each test: " + context.getDisplayName());}
}import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.ExtendWith;@ExtendWith(CustomExtension.class)
public class CustomExtensionTest {@Testpublic void testAdd() {assertEquals(5, 2 + 3);}
}

5. 使用示例:Spring Boot 測試

結(jié)合使用@ExtendWith@SpringBootTest進(jìn)行Spring Boot應(yīng)用程序的集成測試。

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.context.SpringBootTest;
import org.springframework.test.context.junit.jupiter.SpringExtension;
import static org.junit.jupiter.api.Assertions.assertEquals;@ExtendWith(SpringExtension.class)
@SpringBootTest
public class MyApplicationTests {@Autowiredprivate MyService myService;@Testpublic void testAdd() {assertEquals(5, myService.add(2, 3));}
}

總結(jié)

  • JUnit 4中,@RunWith用于指定測試運(yùn)行器,常用的運(yùn)行器包括SpringRunner、ParameterizedSuite等。
  • JUnit 5中,@ExtendWith用于擴(kuò)展測試功能,常用的擴(kuò)展包括SpringExtensionParameterizedTest等。
  • 可以創(chuàng)建自定義運(yùn)行器(JUnit 4)或擴(kuò)展(JUnit 5)來滿足特定測試需求。
  • @SpringBootTest用于Spring Boot應(yīng)用程序的集成測試。

這些工具和技術(shù)使得JUnit能夠靈活地適應(yīng)各種測試需求。

http://www.risenshineclean.com/news/5647.html

相關(guān)文章:

  • 三一重工的網(wǎng)站是哪家做的全自動(dòng)引流推廣軟件
  • 做火影忍者網(wǎng)站的格式seo關(guān)鍵詞優(yōu)化推廣報(bào)價(jià)表
  • 國內(nèi)新聞最新消息10條20235g網(wǎng)絡(luò)優(yōu)化培訓(xùn)
  • 網(wǎng)站文件上傳好下一步怎么做網(wǎng)站友鏈
  • 北京最新網(wǎng)站備案今天最新的新聞?lì)^條新聞
  • 廣州做網(wǎng)站專業(yè)公司2021年新聞?wù)?/a>
  • 手機(jī)網(wǎng)站設(shè)計(jì)小程序網(wǎng)站seo關(guān)鍵詞優(yōu)化技巧
  • 德升武漢網(wǎng)站建設(shè)今天最新軍事新聞視頻
  • 免費(fèi)網(wǎng)站設(shè)計(jì) 優(yōu)幫云公司網(wǎng)絡(luò)優(yōu)化方案
  • 營銷網(wǎng)站建設(shè)公司個(gè)人網(wǎng)站源碼免費(fèi)下載
  • 小說網(wǎng)站開發(fā)思路鄭州網(wǎng)絡(luò)推廣公司
  • 南平網(wǎng)站建設(shè)巨量引擎廣告投放平臺(tái)代理
  • 如何在網(wǎng)站上做淘寶客推廣青島seo外包服務(wù)
  • 廈門市建設(shè)質(zhì)量安全協(xié)會(huì)網(wǎng)站全網(wǎng)營銷平臺(tái)有哪些
  • 做網(wǎng)站招微商賣貨是真的嗎南寧網(wǎng)站優(yōu)化公司電話
  • 成都公司網(wǎng)站設(shè)計(jì)套餐百度快照網(wǎng)址
  • 怎么把網(wǎng)站整站下載長沙網(wǎng)站seo排名
  • 企業(yè)自己如何做網(wǎng)站推廣自己做的網(wǎng)站怎么推廣
  • 網(wǎng)站域名解析設(shè)置免費(fèi)的客戶資源怎么找
  • 網(wǎng)站開發(fā) 基礎(chǔ)教學(xué)視頻設(shè)計(jì)網(wǎng)站免費(fèi)素材
  • 番禺建設(shè)網(wǎng)站服務(wù)seo兼職招聘
  • 公司簡介簡短大氣網(wǎng)站排名優(yōu)化的技巧
  • 刪除百度收錄網(wǎng)站百度灰色關(guān)鍵詞排名
  • 自己做的小網(wǎng)站關(guān)鍵詞排名優(yōu)化江蘇的團(tuán)隊(duì)
  • 易網(wǎng)寧波seo在線優(yōu)化方案
  • 商務(wù)網(wǎng)站構(gòu)建方法關(guān)鍵詞推廣seo怎么優(yōu)化
  • 臨漳網(wǎng)站建站寧波seo優(yōu)化流程
  • 模仿別人的網(wǎng)站東莞關(guān)鍵詞優(yōu)化平臺(tái)
  • 專業(yè)網(wǎng)站建設(shè)咨詢seo優(yōu)化網(wǎng)站教程
  • 微信做網(wǎng)站支付工具廣州疫情最新消息今天封城了