Package com.ustc.SSHDemo.test

Source Code of com.ustc.SSHDemo.test.UserTest

package com.ustc.SSHDemo.test;

import javax.annotation.Resource;

import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.test.annotation.Rollback;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
import org.springframework.transaction.annotation.Transactional;

import com.opensymphony.xwork2.interceptor.annotations.After;
import com.opensymphony.xwork2.interceptor.annotations.Before;
import com.ustc.SSHDemo.user.dao.UserDaoImpl;
import com.ustc.SSHDemo.user.service.UserServiceImpl;
import com.ustc.SSHDemo.user.to.User;

@RunWith(SpringJUnit4ClassRunner.class) //指定测试用例的运行器 这里是指定了Junit4 
@ContextConfiguration(locations = "classpath:applicationContext*.xml")
//@ContextConfiguration({locations =  "classpath:applicationContext*.xml"}) //指定Spring的配置文件 /为classpath下 
//@Transactional //对所有的测试方法都使用事务,并在测试完成后回滚事务 
public class UserTest
//  @Autowired 
//  private ApplicationContext appplicationContext; //自动注入applicationContext,这样就可以使用appli*.getBean("beanName") 
    @Resource       //会自动注入 default by type 
    private UserDaoImpl userDao; 
    @Resource 
    private UserServiceImpl userService; 
     
    @Before //在每个测试用例方法之前都会执行 
    public void init(){
//      System.out.println("&&&&&&&&&&&&&&&&&&&&&");
   
     
    @After //在每个测试用例执行完之后执行 
    public void destory(){ 
    } 
     
    @Test 
//    @Transactional  //使用该注释会使用事务,而且在测试完成之后会回滚事务,也就是说在该方法中做出的一切操作都不会对数据库中的数据产生任何影响 
//    @Rollback(false) //这里设置为false,就让事务不回滚 
    public void testGetByName(){ 
      try {
      User u = userService.getUserById(222);
      System.out.println("**********************$"+u.getId());
    } catch (Exception e) {
      // TODO Auto-generated catch block
      e.printStackTrace();
   
    } 
     
    public void testTest() { 
         
    } 
TOP

Related Classes of com.ustc.SSHDemo.test.UserTest

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.