SpringJunit 单元测试
来源:互联网 发布:淘宝开店教程下载 编辑:程序博客网 时间:2024/05/21 14:03
@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration(locations={"classpath:spring.xml","classpath:spring-hibernate.xml"})
public class TestUserService {
@Autowired
IEmployeeAccountService employeeAccountService;
@BeforeClass
public static void setUpBeforeClass() throws Exception {
}
@AfterClass
public static void tearDownAfterClass() throws Exception {
}
// @Before
// public void setUp() throws Exception {
// ApplicationContext ac = new ClassPathXmlApplicationContext(new String[] { "classpath:spring.xml", "classpath:spring-hibernate.xml" });
// employeeAccountService = (IEmployeeAccountService) ac.getBean("employeeAccountService");
// }
@After
public void tearDown() throws Exception {
}
@Test
public void testUserLogin() {
assertTrue(employeeAccountService.employeeAccountLogin("Admin", "Admin"));
}
}
@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration(locations={"classpath:dispatcher-servlet.xml"})
public class UnitTestBeanInjection {
private static final Logger logger=Logger.getLogger(UnitDemoInjectionTest.class);
// if no bean config in XMl, then you better declare the resource class with @Repository annotation
@Autowired
private UserService userserviceBean0;
// if do not want to use AutoWire, then you can use Resource annotation to find instance default by name
@Resource
private UserService userserviceBean;
@Test
public void testUserService() {
assertNotNull(userserviceBean);
}
@Test
public void testgetUserList() {
// assertNotNull(userserviceBean);
System.out.println(userserviceBean.getUserList().size());
}
@Test
public void testaddUser() {
User u = new User();
u.setName("JUnit");
userserviceBean.addUser(u);
System.out.println(userserviceBean.getUserList().size());
assertEquals(4, userserviceBean.getUserList().size());
}
@Test
public void testshowUser() {
User u = new User();
u = userserviceBean0.showUser("Tom");
assertNotNull(u);
System.out.println(u.getEmail());
}
}
- SpringJunit 单元测试
- 使用SpringJUnit支持 单元测试
- SpringJUnit测试
- springjunit 测试类SpringJUnit4ClassRunner
- 使用springJunit的简单实例:
- 单元测试
- 单元测试
- 单元测试
- 单元测试
- 单元测试
- 单元测试
- 单元测试
- 单元测试
- 单元测试
- 单元测试
- 单元测试
- 单元测试
- 单元测试
- nginx配置(带https)
- zookeeper
- Java消息队列-Spring整合ActiveMq
- 【安全牛学习笔记】XSS的简述
- ……
- SpringJunit 单元测试
- js的循环语句
- ajax跨域问题解决方案
- 创建型模式的讨论
- POJ3057_Evacuation_二分图匹配::逃生问题
- 微信支付开发(1) JS API支付
- 210. Course Schedule II
- dedecms获取上传图片地址(其实这个方法在哪里都可以获取)
- 每天一个python模块之Requests