成人在线亚洲_国产日韩视频一区二区三区_久久久国产精品_99国内精品久久久久久久

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

java - Mavn執(zhí)行測(cè)試時(shí)<scope>test</scope>導(dǎo)致錯(cuò)誤

瀏覽:138日期:2023-11-25 17:43:19

問(wèn)題描述

學(xué)習(xí)maven test時(shí),執(zhí)行mvn test時(shí),會(huì)找不到org.junit在pom.xml中已經(jīng)引入

<dependencies><dependency> <groupId>joda-time</groupId> <artifactId>joda-time</artifactId> <version>2.2</version></dependency><dependency> <groupId>junit</groupId> <artifactId>junit</artifactId> <version>4.12</version> <scope>test</scope></dependency> </dependencies>

報(bào)錯(cuò)信息如下java - Mavn執(zhí)行測(cè)試時(shí)<scope>test</scope>導(dǎo)致錯(cuò)誤文件目錄如下java - Mavn執(zhí)行測(cè)試時(shí)<scope>test</scope>導(dǎo)致錯(cuò)誤hello目錄下存在如下文件java - Mavn執(zhí)行測(cè)試時(shí)<scope>test</scope>導(dǎo)致錯(cuò)誤其中GreeterTest為測(cè)試

執(zhí)行mvn compile 或者mvn package也會(huì)報(bào)錯(cuò)

當(dāng)把pom.xml中junit依賴(lài)的scope去掉時(shí),編譯和測(cè)試都能成功。

<dependencies><dependency> <groupId>joda-time</groupId> <artifactId>joda-time</artifactId> <version>2.2</version></dependency><dependency> <groupId>junit</groupId> <artifactId>junit</artifactId> <version>4.12</version></dependency> </dependencies>

造成這個(gè)的原因是什么?maven在執(zhí)行compile時(shí)同時(shí)編譯*Test的文件嗎,那么為什么mvn test也不能成功?mvn test不是會(huì)自動(dòng)執(zhí)行*Test的文件嗎?而且scope test確定了測(cè)試時(shí)會(huì)引入junit

問(wèn)題解答

回答1:

這個(gè)問(wèn)題其實(shí)你因?yàn)槟悴皇煜aven文件結(jié)構(gòu)所致.測(cè)試類(lèi)一般是放在src/test/java,而不是放在src/main/java下.maven在編譯的時(shí)候,src/main/java下是不引用<scope>test</scope>的jar,而編譯src/test/java下的測(cè)試這會(huì)引用<scope>test</scope>的jar

標(biāo)簽: java
相關(guān)文章: