使用spring测试模块

既然我们要使用到spring测试的模块那我们肯定就需要到pom文件里面导入一个spring测试的jar包,那么至于详细导那个包,还得看你的junit的版本号,要与junit的版本号相近的版本号的包,如下:
在pom.xml文件里面编写

junit的jar包的路径

<dependency>
		<groupId>junit</groupId>
		<artifactId>junit</artifactId>
		<version>4.12</version>
		<scope>test</scope>
</dependency>

spring-test的jar包的路径

<dependency>
    <groupId>org.springframework</groupId>
    <artifactId>spring-test</artifactId>
    <version>4.3.13.RELEASE</version>
    <scope>test</scope>
</dependency>

导入包之后我们就要开始编写spring测试模块了,那么测试类放在哪儿呢:如图所示:
在这里插入图片描述
代码如下:
TestMapper.java

package com.anzhuo.cm.test;

import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;

import com.anzhuo.cm.dao.SaattendanceMapper;
import com.anzhuo.cm.pojo.Saattendance;


@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration(locations = "classpath:spring.xml")
public class TestMapper {
	
   @Autowired
   SaattendanceMapper sm;
 
	@Test
	public void test(){
		Saattendance ss =  sm.selectByPrimaryKey(1);
		System.out.println(ss.getsNumber());
		System.out.println(ss.getSaTruant());
		
	}
}

这样就可以测试啦,能查询出来的话,说明成功

  • 1
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值