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

来源:互联网 发布:淘宝网换货预约快递 编辑:程序博客网 时间:2024/05/20 02:25

 测试的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 extendsAbstractBasicService<User, Integer> implements UserServiceIf {public UserServiceImpl() {super(User.class);}@Transactional(propagation = Propagation.NOT_SUPPORTED, readOnly = true)@Overridepublic 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 测试信息

原创粉丝点击