JAVA全系列 教程
3762个小节阅读:7094.1k
目录
C语言快速入门
JAVA全系列 教程
面向对象的程序设计语言
Python全系列 教程
Python3.x版本,未来主流的版本
人工智能 教程
顺势而为,AI创新未来
大厂算法 教程
算法,程序员自我提升必经之路
C++ 教程
一门通用计算机编程语言
微服务 教程
目前业界流行的框架组合
web前端全系列 教程
通向WEB技术世界的钥匙
大数据全系列 教程
站在云端操控万千数据
AIGC全能工具班
A A
White Night
保证项目中除了spring-context依赖以外,还需要导入
xxxxxxxxxx
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-api</artifactId>
<version>5.9.2</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-test</artifactId>
<version>6.0.6</version>
<scope>test</scope>
</dependency>
新建配置文件applicationContext-test.xml
xxxxxxxxxx
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:context="http://www.springframework.org/schema/context"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans.xsd
http://www.springframework.org/schema/context
https://www.springframework.org/schema/context/spring-context.xsd">
<context:component-scan base-package="com.bjsxt.test"></context:component-scan>
</beans>
新建类com.bjsxt.test.Student
xxxxxxxxxx
@Component
@Data
public class Student {
private int id;
private String name;
}
新建测试类。
使用@SpringJunitConfig注解,让Junit Jupiter生效
xxxxxxxxxx
@SpringJUnitConfig
@ContextConfiguration("classpath:applicationContext-test.xml")
public class JunitJupiterTest {
@Autowired
Student student;
@Test
void test(){
System.out.println(student);
}
}