junit4/5 getDefaultClassLoader()Ljava/lang/ClassLoader;
生活随笔
收集整理的這篇文章主要介紹了
junit4/5 getDefaultClassLoader()Ljava/lang/ClassLoader;
小編覺得挺不錯(cuò)的,現(xiàn)在分享給大家,幫大家做個(gè)參考.
問題出現(xiàn)原因
最終解決通過 Maven Helper 查看了依賴,發(fā)現(xiàn)了正真測(cè)試的時(shí)候使用的是 springboot 中的 jupiter
查看了 springboot parent 中的依賴,發(fā)現(xiàn)以下配置
<!--parent 中的配置--> <junit-jupiter.version>5.5.2</junit-jupiter.version> <!--通過上面的版本映入了 一個(gè) bom,可能是因?yàn)檫@個(gè) bom 里的依賴版本造成的問題--> <dependency><groupId>org.junit</groupId><artifactId>junit-bom</artifactId><version>${junit-jupiter.version}</version><type>pom</type><scope>import</scope> </dependency><!--測(cè)試項(xiàng)目 中的配置--> <junit.jupiter.version>5.0.0-M4</junit.jupiter.version> <!--將測(cè)試項(xiàng)目中的配置修改為,即可成功運(yùn)行--> <junit-jupiter.version>5.0.0-M4</junit.jupiter.version>`
使用 Junit 4 成功用例
<?xml version="1.0" encoding="UTF-8"?> <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd"><modelVersion>4.0.0</modelVersion><parent><groupId>org.springframework.boot</groupId><artifactId>spring-boot-starter-parent</artifactId><version>2.2.1.RELEASE</version><relativePath/> <!-- lookup parent from repository --></parent><groupId>com.example</groupId><artifactId>demoda</artifactId><version>0.0.1-SNAPSHOT</version><name>demoda</name><description>Demo project for Spring Boot</description><properties><java.version>1.8</java.version></properties><dependencies><dependency><groupId>org.springframework.boot</groupId><artifactId>spring-boot-starter</artifactId></dependency><dependency><groupId>org.springframework.boot</groupId><artifactId>spring-boot-starter-test</artifactId><scope>test</scope><exclusions><exclusion><groupId>org.junit.jupiter</groupId><artifactId>junit-jupiter-api</artifactId></exclusion></exclusions></dependency></dependencies> </project>使用 Junit 5 成功用例
<?xml version="1.0" encoding="UTF-8"?> <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd"><modelVersion>4.0.0</modelVersion><parent><groupId>org.springframework.boot</groupId><artifactId>spring-boot-starter-parent</artifactId><version>2.2.1.RELEASE</version><relativePath/> <!-- lookup parent from repository --></parent><groupId>com.example</groupId><artifactId>demoda</artifactId><version>0.0.1-SNAPSHOT</version><name>demoda</name><description>Demo project for Spring Boot</description><properties><java.version>1.8</java.version></properties><dependencies><dependency><groupId>org.springframework.boot</groupId><artifactId>spring-boot-starter</artifactId></dependency><dependency><groupId>org.springframework.boot</groupId><artifactId>spring-boot-starter-test</artifactId><scope>test</scope><exclusions><exclusion><groupId>org.junit.jupiter</groupId><artifactId>junit-jupiter-api</artifactId></exclusion></exclusions></dependency></dependencies> </project>測(cè)試?yán)?/h4>
*/
@SpringBootTest
@RunWith(SpringJUnit4ClassRunner.class)
public class ServiceHospApplicationTest {@Autowiredprivate MongoTemplate mongoTemplate;@Testpublic void createUser() {User user = new User();user.setName("張三");user.setAge(27);user.setEmail("yinhaoye@qq.com");User userMongo = mongoTemplate.insert(user);System.out.println(userMongo);}
}
總結(jié)
以上是生活随笔為你收集整理的junit4/5 getDefaultClassLoader()Ljava/lang/ClassLoader;的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 支付宝接口的调用
- 下一篇: jvisualvm安装Visual GC