下载junit包:http://sourceforge.net/projects/junit/?source=directory
将junit.jar放到项目lib文件夹中。
一、测试Servcie层
1、添加SpringTestBase类
新建UserServiceTest类 ,该类需继承SpringTestBase类
将junit.jar放到项目lib文件夹中。
一、测试Servcie层
1、添加SpringTestBase类
package com.hsinghsu.testSSH;
import org.junit.runner.RunWith;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
import org.springframework.test.context.transaction.TransactionConfiguration;
import org.springframework.transaction.annotation.Transactional;
@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration(locations = {"classpath*:applicationContext*.xml"})
@Transactional
@TransactionConfiguration(transactionManager = "transactionManager", defaultRollback = false)
public class SpringTestBase {
}
2、测试Service层
新建UserServiceTest类 ,该类需继承SpringTestBase类
package com.hsinghsu.testSSH.service;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertTrue;
import org.junit.Test;
import org.springframework.beans.factory.annotation.Autowired;
import com.hsinghsu.testSSH.SpringTestBase;
public class UserServiceTest extends SpringTestBase
{
@Autowired
private UserService userService;
@Test
public void testConfig()