spring3.0.2 junit 接口测试问题

 

 

/**

 * 

 * Description:

 * 

 * @RunWith - JUnit annotation that specifies that the Spring class runner

 *          should be used for running the test.

 * @ContextConfiguration - Specifies the location of your Spring application

 *                       context xml file(s). This gets inherited by subclasses,

 *                       so you can use it in a base class to configure all of

 *                       the tests in your application.

 * @Test - Indicates that the method should be run as a test. Note that although

 *       I used the pre JUnit 4 naming conventions (class names postfixed with

 *       "Test" and method names prefixed with "test"), this is not a

 *       requirement.

 * @Ignore - When this annotation is added, the associated test method will not

 *         be run. This is a great alternative to commenting out the methods

 *         which was required prior to JUnit 4. In this case, the test would

 *         fail if the

 * @Ignore annotation wasn't used because objectUnderTest.getSomethingFalse()

 *         does not equal true.

 * @Autowired - Indicates that Spring should "wire" this dependency when

 *            initializing the test. In this case, a Spring bean named

 *            objectUnderTest will be provided.

 * 

 * 

 *            要创建一个基于Spring2.5的JUnit4.4测试用例其实相当简单,主要进行以下几步的工作:

 *            (1)创建一个扩展自AbstractTransactionalJUnit4SpringContextTests的类

 *            ,该基类是Spring2

 *            .5为方便在JUnit4环境进行事务测试的类,它还提供了一个simpleJdbcTemplate属性让你可以方便地操控数据库表

 *            ,便于对测试数据进行有效的操作;

 *            (2)用@ContextLocation注解指定你要加载的Spring配置信息所在的位置;(默认的加载文件信息请参阅Spring

 *            Documentation); (3)用@Autowired或@Resource注解注入你的Service接口,@Autowrired是指按类型将Spring

 *            Bean注入;而@Resource则按名称将Spring Bean注入。

 *            (4)用@Before准备待测试的数据,如果我们的数据库表结构没有任何数据

 *            ,则可以在这里预先插入记录,以便进行单元测试,当整个测试完成后,这些数据都不会被保留在数据库中。

 *            (5)在需要进行测试的方法上使用JUnit4.4提供的@Test注解进行标示;

 * 

 * 

 *            Test类可以选择继承 extends AbstractTransactionalJUnit4SpringContextTests

 * 

 * 

 *            Copyright (c) 2008-2009 paraDise sTudio(DT). All Rights Reserved.

 * @version 1.0 Apr 13, 2009 5:08:34 PM

 *          mousepotato(paradise.lsj#gmail.com)created

 */

 

@RunWith(SpringJUnit4ClassRunner.class)

// applicationContext*.xml这种匹配写法,是不支持的,有多少个配置文件,就引入多少个。

@ContextConfiguration(locations = {"classpath:conf/spring/spring_base.xml"})

// @TestExecutionListeners({DependencyInjectionTestExecutionListener.class})

public class LoginTest {

private static Logger log = Logger.getLogger(ILoginService.class);

 

public LoginTest() {

super();

}

 

private ILoginService loginService;

 

 

        @Autowired(required = false)

   @Qualifier("loginService")//由于可以有n多类去实现接口,这个地方需要注明实现接口的类。

public void setLoginService(ILoginService loginService) {

this.loginService = loginService;

}

}

 

 

 

@Transactional

@Service("loginService")

public class LoginServiceImpl implements ILoginService {

 

}

 

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值