1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 | package com.baobaotao.service; import org.springframework.test.context.junit4. AbstractTransactionalJUnit4SpringContextTests; import org.springframework.test.context.ContextConfiguration; import org.springframework.beans.factory.annotation.Autowired; import org.junit.Test; import com.baobaotao.domain.User; import java.util.Date; @ContextConfiguration //① public class TestUserService extends AbstractTransactionalJUnit4SpringContextTests { @Autowired //② private UserService userService; @Test //③ public void handleUserLogin(){ User user = new User(); user.setUserId(1); user.setLastIp("127.0.0.1"); Date now = new Date(); user.setLastVisit(now.getTime()); userService.handleUserLogin(user); } } |
1 2 3 4 5 6 7 8 | @ContextConfiguration(locations={"base-context.xml"}) public class BaseTest { // ... } @ContextConfiguration(locations={"extended-context.xml"}) public class ExtendedTest extends BaseTest { // ... } |
1 2 3 4 5 6 7 8 9 10 | <?xml version="1.0" encoding="UTF-8" ?> <beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.5.xsd"> <!-- ① 引入清单1定义的Spring配置文件 --> <import resource="classpath:/applicationContext.xml"/> </beans> |
欢迎光临 电子技术论坛_中国专业的电子工程师学习交流社区-中电网技术论坛 (http://bbs.eccn.com/) | Powered by Discuz! 7.0.0 |