久久r热视频,国产午夜精品一区二区三区视频,亚洲精品自拍偷拍,欧美日韩精品二区

您的位置:首頁技術(shù)文章
文章詳情頁

Junit springboot打印測試方法信息

瀏覽:122日期:2023-05-21 08:19:29

有時候需要使用junit做測試。方便日后參考。

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

pom.xml引入依賴jar包

<!-- 測試 --> <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><!--這個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測試類

能打印當前方法是哪個test主要是下面這句話

@Rulepublic TestName junitClass= new TestName();

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

@Log4j2

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

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

完整測試類

@RunWith(SpringRunner.class)@SpringBootTest(classes = SearchServerApplication.class)@Log4j2public 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('耗時 ' + usedtime + ' my'); System.out.println(junitClass.getMethodName() + '....................end....................'); } @Test public void methodtest() { log.info(junitClass.getMethodName() + '測試'); }}

運行結(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測試耗時 0.008 mymethodtest....................end....................

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

Junit springboot打印測試方法信息

以上就是本文的全部內(nèi)容,希望對大家的學習有所幫助,也希望大家多多支持好吧啦網(wǎng)。

標簽: Spring
相關(guān)文章:
主站蜘蛛池模板: 北流市| 台北市| 大英县| 安图县| 南木林县| 伊宁市| 容城县| 娱乐| 香河县| 治县。| 安宁市| 阿城市| 达州市| 玉山县| 香河县| 淮北市| 奎屯市| 河北区| 得荣县| 宝应县| 赫章县| 社旗县| 囊谦县| 衡东县| 清水河县| 惠州市| 丹巴县| 鲁甸县| 高尔夫| 梨树县| 诸城市| 郯城县| 峨眉山市| 余庆县| 鹿邑县| 长宁区| 邢台县| 河东区| 秭归县| 合阳县| 云阳县|