06 Spring使用Junit
2019-03-04 本文已影响0人
0640fefbc8bf
首先在pom.xml中添加依赖
<!--spring-test依赖-->
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-test</artifactId>
<version>${spring.version}</version>
</dependency>
注意:这里的<version>${spring.version}</version>是通过propertise中添加spring.version(全局修改)
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<maven.compiler.source>1.8</maven.compiler.source>
<maven.compiler.target>1.8</maven.compiler.target>
<spring.version>5.0.10.RELEASE</spring.version>
</properties>
创建一个Max类比较大小

在配置文件中配置Max的bean
<!--配置一个Max的bean-->
<bean id="max" class="com.spring.IoC.Max">
<constructor-arg name="a" value="5"/>
<constructor-arg name="b" value="3"/>
</bean>
将光标放在Class Max按下ALT+enter出现
QQ截图20190304170545.png
勾选测试方法

输入(@Autowired 自动注入: 配置文件给值)
@RunWith(SpringJUnit4ClassRunner.class)//反射
//指定配置文件路径
@ContextConfiguration(locations = {"/spring.xml"})
