junit的使用说明

    前言:一直以来自己写的程序都是网络上已经搭建好的了,自己只要按照里面的例子来进行就能够快速掌握了,对于里面的很多细节自己也没有在意,也没有时间去花那个功夫研究下,今天想在一个糟糕的二期项目中进行junit的测试,然后很多的细节问题就来了。

1,在maven中添加junti的jar

                <!-- Test -->
		<dependency>
			<groupId>junit</groupId>
			<artifactId>junit</artifactId>
			<version>4.10</version>
			<scope>test</scope>
		</dependency>

2,创建程序包

111534_kNDO_817904.png

3,编写类

package wx;

import net.sf.json.JSONArray;

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.zp.mapper.WxJoinMapper;
import com.zp.model.WxJoin;

@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration(locations = { "classpath:config/spring-common.xml",
		"classpath:config/mybatis-config.xml" })
public class WxJoinTest {
	@Autowired
	WxJoinMapper joinMapper;

	@Test
	public void save() {
		if (joinMapper == null) {
			System.out.println("空");
		}
		WxJoin findById = joinMapper.findById(1);
		JSONArray fromObject = JSONArray.fromObject(findById);
		System.out.println(fromObject.toString());
	}
}

如果这个时候运行的话,会报:Class not found wx.WxJoinTest

为什么呢,我指定了默认编译的路径是:zpwxms/WebRoot/WEB-INF/classes,之所以指定是因为发布到tomcat的时候,zpwxms/WebRoot/WEB-INF/classes没有编译的类和相关的jar;而junit的类路径为:target/classes;

4,解决办法

这样的话,我们就要进行配置,如图:test目录进行该,src目录也相同。我就不截图了113700_AfSi_817904.png

ok,在运行看看,没有问题啦!


转载于:https://my.oschina.net/u/817904/blog/657238

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值