spring-test几种用法

版权声明:本文为博主原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明。
本文链接:https://blog.csdn.net/ZYJ_2012/article/details/74461226

maven:

<properties>
    <spring_version>4.3.4.RELEASE</spring_version>
</properties>
<dependency>
    <groupId>org.springframework</groupId>
    <artifactId>spring-test</artifactId>
    <version>${spring_version}</version>
    <scope>test</scope>
</dependency>
<dependency>
    <groupId>junit</groupId>
    <artifactId>junit</artifactId>
    <version>4.12</version>
    <scope>test</scope>
</dependency>
@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration(classes = {EventConf.class})
public class DemoTest {
    @Autowired
    private DemoPublisher publisher;
    @Test
    public void eventTest(){
        publisher.push("发布消息");
    }
}
@Configuration
@ComponentScan("com.listener")
public class EventConf {
}
方式二:

@ContextConfiguration(locations = {"classpath:/test*.xml"})
public class UserLoginMapperTest extends AbstractJUnit4SpringContextTests {

    String collectionName = CollectionConstants.COLL_USER_LOGIN;
    @Resource
    UserLoginMapper userLoginMapper;

    @Test
    public void findById_test(){
        UserLogin condition = new UserLogin();
        condition.setLoginId("18221688041");
        List<UserLogin> userLogins = userLoginMapper.findByCondition(condition);
        System.err.println(userLogins);
    }
}

展开阅读全文

没有更多推荐了,返回首页