[使用心得]maven2之m2eclipse使用手册之四编写通用Dao实例(四)

测试的bean:

@Entity
@Table(name="users")
public class User extends AbstractBean{
    
    
    private static final long serialVersionUID = -2512193728050258334L;
    
   
    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    public final Integer getId() {
        return id;
    }
    @Column(length=50,nullable=false)
    public String getUserid() {
        return userid;
    }
    
    @Column(length=1)
    public Integer getUsertype() {
        return usertype;
    }
    @Column(length=2)
    public Integer getRoleid() {
        return roleid;
    }
    @Column(length=50)
    public String getUseragent() {
        return useragent;
    }
  
    @Column(length=100)
    public String getNickname() {
        return nickname;
    }
    @Column(length=50)
    public String getName() {
        return name;
    }
    
    @Column(length=10)
    public String getSex() {
        return sex;
    }
    @Column(length=6)
    public Short getAge() {
        return age;
    }
    @Column(length=20)
    public String getCardid() {
        return cardid;
    }
    @Column(length=50)
    public String getEmail() {
        return email;
    }
    @Column(length=50)
    public String getPassword() {
        return password;
    }
    @Temporal(TemporalType.DATE)
    public Date getRgtime() {
        return rgtime;
    }
    @Temporal(TemporalType.DATE)
    public Date getUptime() {
        return uptime;
    }
    @Column(length=1)
    public String getStatus() {
        return status;
    }
    @Column(length=1)
    public String getOpenifno() {
        return openifno;
    }
    @Column(length=1)
    public Byte getActivestatus() {
        return activestatus;
    }
  
    @Column(length=20)
    public String getActivecode() {
        return activecode;
    }

测试的Service:把User.class注入到AbstractBasicService中

@Service("userService")
public class UserServiceImpl extends
        AbstractBasicService<User, Integer> implements
        UserServiceIf {
 
    public UserServiceImpl() {
        super(User.class);
 
    }
    @Transactional(propagation = Propagation.NOT_SUPPORTED, readOnly = true)
    @Override
    public List<User> listAllUser() {
     
        return findAll();
    }
}

测试用例(写入src/test/java中):

@ContextConfiguration("classpath:applicationContext.xml")
public class UserTest extends AbstractJUnit4SpringContextTests {
 
    private UserServiceIf userService;
 
 
    public final UserServiceIf getUserService() {
        return userService;
    }
    @Resource(name = "userService")
    public final void setUserService(final UserServiceIf userService) {
        this.userService = userService;
    }
 
    @Test
    public void testUserList() {
        Assert.assertNotNull(userService.listAllUser());
    }
 
}

然后对maven的项目选择maven test (如图1:运行maven test)会出现Tests(如图2:测试信息)的信息,会返回运行了多少个程序,失败有多少个,错误有多少个,跳过该程序有多少个,如果不喜欢maven 那种测试方案的话,可以对该类进行直接的junit测试也可以.

image 图1 运行maven test

image 图2 测试信息

转载于:https://www.cnblogs.com/edwardlauxh/archive/2010/06/03/1918580.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值