欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

Junit springboot打印測(cè)試方法信息

 更新時(shí)間:2020年04月26日 11:42:45   作者:a393060727  
這篇文章主要介紹了Junit springboot打印測(cè)試方法信息,文中通過(guò)示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友可以參考下

有時(shí)候需要使用junit做測(cè)試。方便日后參考。

目前流行的springboot 的junit測(cè)試,在很多時(shí)候需要使用。當(dāng)前執(zhí)行的方法是什么,我們只需要引入用注解方法就可以了。

pom.xml引入依賴jar包

<!-- 測(cè)試 -->
    <dependency>
      <groupId>org.springframework.boot</groupId>
      <artifactId>spring-boot-starter-test</artifactId>
      <scope>test</scope>
    </dependency>
    <dependency>
     <groupId>org.junit.jupiter</groupId>
     <artifactId>junit-jupiter-engine</artifactId>
     </dependency>
    <dependency>
     <groupId>org.junit.platform</groupId>
     <artifactId>junit-platform-launcher</artifactId>
    </dependency><!--這個(gè)alibaba的json也加入下-->
		<dependency>		 <groupId>com.alibaba</groupId>		 <artifactId>fastjson</artifactId>		 <version>1.2.62</version>		</dependency>
<!--Lombok-->		<dependency>			<groupId>org.projectlombok</groupId>			<artifactId>lombok</artifactId>			<scope>provided</scope>		</dependency>

junit測(cè)試類

能打印當(dāng)前方法是哪個(gè)test主要是下面這句話

@Rule
public TestName junitClass= new TestName();

引用了lombok包后,log使用如下注解

@Log4j2

在代碼中可直接使用log,就可以了,不用再使用一大串

private Logger log = LoggerFactory.getLogger(getClass());

完整測(cè)試類

@RunWith(SpringRunner.class)
@SpringBootTest(classes = SearchServerApplication.class)
@Log4j2
public class CmyDicServiceTest {private Long starttime;
  @Rule
  public TestName junitClass= new TestName();
  @Before
  public void before() {
    starttime = System.currentTimeMillis();
    System.out.println(junitClass.getMethodName() + "....................start....................");
  }
  @After
  public void after() {
    double usedtime = (System.currentTimeMillis() - starttime) / 1000.0;
    System.out.println("耗時(shí) " + usedtime + " my");
    System.out.println(junitClass.getMethodName() + "....................end....................");
  }
  @Test
  public void methodtest() {
    log.info(junitClass.getMethodName() + "測(cè)試");
  }
}

運(yùn)行結(jié)果

2020-04-23 10:06:58.558 INFO [my-server-search,,,] 51088 --- [      main] com.test.mq.CmyDicServiceTest      : Started CmyDicServiceTest in 65.613 seconds (JVM running for 68.844)
methodtest....................start....................
2020-04-23 10:06:59.361 INFO [my-server-search,,,] 51088 --- [      main] com.test.mq.CmyDicServiceTest      : methodtest測(cè)試
耗時(shí) 0.008 my
methodtest....................end....................

可以看到已經(jīng)打印出當(dāng)前執(zhí)行的方法是methodtest

以上就是本文的全部?jī)?nèi)容,希望對(duì)大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。

相關(guān)文章

  • java多線程入門知識(shí)及示例程序

    java多線程入門知識(shí)及示例程序

    java多線程入門知識(shí)及示例程序,大家參考使用吧
    2013-12-12
  • HashMap容量和負(fù)載因子使用說(shuō)明

    HashMap容量和負(fù)載因子使用說(shuō)明

    這篇文章主要介紹了HashMap容量和負(fù)載因子使用說(shuō)明,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。一起跟隨小編過(guò)來(lái)看看吧
    2020-09-09
  • Java上傳文件圖片到服務(wù)器的方法

    Java上傳文件圖片到服務(wù)器的方法

    這篇文章主要為大家詳細(xì)介紹了Java上傳文件圖片到服務(wù)器的方法,具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下
    2018-01-01
  • 詳解SpringMVC重定向傳參數(shù)的實(shí)現(xiàn)

    詳解SpringMVC重定向傳參數(shù)的實(shí)現(xiàn)

    本篇文章主要介紹了詳解SpringMVC重定向傳參數(shù)的實(shí)現(xiàn),我們可以使用重定向的方式,改變?yōu)g覽器的地址欄,防止表單因?yàn)樗⑿轮貜?fù)提交。有興趣的可以了解一下。
    2017-01-01
  • Java發(fā)送郵件遇到的常見(jiàn)需求匯總

    Java發(fā)送郵件遇到的常見(jiàn)需求匯總

    這篇文章主要介紹了Java發(fā)送郵件遇到的常見(jiàn)需求匯總的相關(guān)資料,非常不錯(cuò),具有參考借鑒價(jià)值,需要的朋友可以參考下
    2016-06-06
  • springboot?無(wú)法自動(dòng)裝配的問(wèn)題

    springboot?無(wú)法自動(dòng)裝配的問(wèn)題

    這篇文章主要介紹了springboot?無(wú)法自動(dòng)裝配的問(wèn)題,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。如有錯(cuò)誤或未考慮完全的地方,望不吝賜教
    2022-01-01
  • maven報(bào)錯(cuò):Failed to execute goal on project問(wèn)題及解決

    maven報(bào)錯(cuò):Failed to execute goal on p

    這篇文章主要介紹了maven報(bào)錯(cuò):Failed to execute goal on project問(wèn)題及解決方案,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。如有錯(cuò)誤或未考慮完全的地方,望不吝賜教
    2023-04-04
  • Spring Boot設(shè)置并使用緩存的步驟

    Spring Boot設(shè)置并使用緩存的步驟

    今天小編就為大家分享一篇關(guān)于Spring Boot設(shè)置并使用緩存的步驟,小編覺(jué)得內(nèi)容挺不錯(cuò)的,現(xiàn)在分享給大家,具有很好的參考價(jià)值,需要的朋友一起跟隨小編來(lái)看看吧
    2019-03-03
  • Java 合并多個(gè)MP4視頻文件

    Java 合并多個(gè)MP4視頻文件

    這篇文章主要介紹了Java 合并多個(gè)MP4視頻文件的方法,幫助大家利用Java處理視頻,提高辦公效率,感興趣的朋友可以了解下
    2020-11-11
  • 不規(guī)范使用ThreadLocal導(dǎo)致bug分析解決

    不規(guī)范使用ThreadLocal導(dǎo)致bug分析解決

    這篇文章主要為大家介紹了不規(guī)范使用ThreadLocal導(dǎo)致bug分析解決,有需要的朋友可以借鑒參考下,希望能夠有所幫助,祝大家多多進(jìn)步,早日升職加薪
    2023-01-01

最新評(píng)論