如何将CodePro Analytix与Spring MVC项目一起用于jUnit生成?
我们正在评估生成JUnit。我们正在spring3.0中进行一个web项目。到目前为止,CodePro正在生成无用的JUnit。它生成相同的测试用例。(我已经按照手册的建议指定了spring-test.jar)如何将CodePro Analytix与Spring MVC项目一起用于jUnit生成?,spring,spring-mvc,codepro,Spring,Spring Mvc,Codepro,我们正在评估生成JUnit。我们正在spring3.0中进行一个web项目。到目前为止,CodePro正在生成无用的JUnit。它生成相同的测试用例。(我已经按照手册的建议指定了spring-test.jar) 如果您在Spring项目中使用此工具生成jUnit,请提供帮助。我假设我们必须在某个地方指定spring配置xml,否则它将如何了解DI。此外,我们可能需要模拟一些所需的对象,但不确定。完成codepro插件设置后,右键单击类或包->选择生成Junit测试用例 它将为您的类生成测试类。然
如果您在Spring项目中使用此工具生成jUnit,请提供帮助。我假设我们必须在某个地方指定
spring配置
xml,否则它将如何了解DI。此外,我们可能需要模拟一些所需的对象,但不确定。完成codepro插件设置后,右键单击类或包->选择生成Junit测试用例
它将为您的类生成测试类。然后在setup方法中,您必须设置spring配置XML
ServiceFacadeImpl.Java:
public class ServiceFacadeImpl implements ServiceFacade {
private ServiceDAO serviceDAO;
@Override
public ServiceVO getService(int serviceId) {
return (ServiceVO) serviceDAO.getById(serviceId);
}
@Override
public List<ServiceVO> getServices() {
String criteria = " WHERE activeSwitch='Y' ORDER BY lastUpdatedDt DESC";
return (List<ServiceVO>) serviceDAO.getAll(criteria);
}
/**
* @return the serviceDAO
*/
public ServiceDAO getServiceDAO() {
return serviceDAO;
}
/**
* @param serviceDAO
* the serviceDAO to set
*/
public void setServiceDAO(ServiceDAO serviceDAO) {
this.serviceDAO = serviceDAO;
}
}
public class ServiceFacadeImplTest {
private ServiceFacadeImpl serviceFacadeImpl;
ServiceFacadeImpl fixture = null;
/**
* Run the ServiceVO getService(int) method test.
*
* @throws Exception
*
* @generatedBy CodePro at 7/7/13 10:34 PM
*/
@Test
public void testGetService_1() throws Exception {
List<ServiceVO> result = fixture.getServices();
int serviceId = 0;
ServiceVO result1 = fixture.getService(1);
assertNotNull(result1);
}
/**
* Run the List<ServiceVO> getServices() method test.
*
* @throws Exception
*
* @generatedBy CodePro at 7/7/13 10:34 PM
*/
@Test
public void testGetServices_1() throws Exception {
List<ServiceVO> result = fixture.getServices();
assertNotNull(result);
}
/**
* Perform pre-test initialization.
*
* @throws Exception
* if the initialization fails for some reason
*
* @generatedBy CodePro at 7/7/13 10:34 PM
*/
@SuppressWarnings("resource")
@Before
public void setUp() throws Exception {
this.setServiceFacadeImpl((ServiceFacadeImpl) new ClassPathXmlApplicationContext(
"applicationContext-facade.xml").getBean("serviceFacade"));
fixture = this.getServiceFacadeImpl();
}
/**
* Perform post-test clean-up.
*
* @throws Exception
* if the clean-up fails for some reason
*
* @generatedBy CodePro at 7/7/13 10:34 PM
*/
@After
public void tearDown() throws Exception {
// Add additional tear down code here
}
/**
* Launch the test.
*
* @param args
* the command line arguments
*
* @generatedBy CodePro at 7/7/13 10:34 PM
*/
public static void main(String[] args) {
new org.junit.runner.JUnitCore().run(ServiceFacadeImplTest.class);
}
/**
* @return the serviceFacadeImpl
*/
public ServiceFacadeImpl getServiceFacadeImpl() {
return serviceFacadeImpl;
}
/**
* @param serviceFacadeImpl
* the serviceFacadeImpl to set
*/
public void setServiceFacadeImpl(ServiceFacadeImpl serviceFacadeImpl) {
this.serviceFacadeImpl = serviceFacadeImpl;
}
}
公共类ServiceFacadeImpl实现ServiceFacade{
私人服务;
@凌驾
public ServiceVO getService(int serviceId){
return(ServiceVO)serviceDAO.getById(serviceId);
}
@凌驾
公共列表服务(){
String criteria=“WHERE activeSwitch='Y'ORDER BY lastUpdatedt DESC”;
返回(列表)serviceDAO.getAll(标准);
}
/**
*@returntheservicedao
*/
公共服务dao getServiceDAO(){
返回serviceDAO;
}
/**
*@param serviceDAO
*要设置的serviceDAO
*/
公共无效设置ServiceDAO(ServiceDAO ServiceDAO){
this.serviceDAO=serviceDAO;
}
}
*Codepro生成类*
ServiceFacadeImplTest.java:
public class ServiceFacadeImpl implements ServiceFacade {
private ServiceDAO serviceDAO;
@Override
public ServiceVO getService(int serviceId) {
return (ServiceVO) serviceDAO.getById(serviceId);
}
@Override
public List<ServiceVO> getServices() {
String criteria = " WHERE activeSwitch='Y' ORDER BY lastUpdatedDt DESC";
return (List<ServiceVO>) serviceDAO.getAll(criteria);
}
/**
* @return the serviceDAO
*/
public ServiceDAO getServiceDAO() {
return serviceDAO;
}
/**
* @param serviceDAO
* the serviceDAO to set
*/
public void setServiceDAO(ServiceDAO serviceDAO) {
this.serviceDAO = serviceDAO;
}
}
public class ServiceFacadeImplTest {
private ServiceFacadeImpl serviceFacadeImpl;
ServiceFacadeImpl fixture = null;
/**
* Run the ServiceVO getService(int) method test.
*
* @throws Exception
*
* @generatedBy CodePro at 7/7/13 10:34 PM
*/
@Test
public void testGetService_1() throws Exception {
List<ServiceVO> result = fixture.getServices();
int serviceId = 0;
ServiceVO result1 = fixture.getService(1);
assertNotNull(result1);
}
/**
* Run the List<ServiceVO> getServices() method test.
*
* @throws Exception
*
* @generatedBy CodePro at 7/7/13 10:34 PM
*/
@Test
public void testGetServices_1() throws Exception {
List<ServiceVO> result = fixture.getServices();
assertNotNull(result);
}
/**
* Perform pre-test initialization.
*
* @throws Exception
* if the initialization fails for some reason
*
* @generatedBy CodePro at 7/7/13 10:34 PM
*/
@SuppressWarnings("resource")
@Before
public void setUp() throws Exception {
this.setServiceFacadeImpl((ServiceFacadeImpl) new ClassPathXmlApplicationContext(
"applicationContext-facade.xml").getBean("serviceFacade"));
fixture = this.getServiceFacadeImpl();
}
/**
* Perform post-test clean-up.
*
* @throws Exception
* if the clean-up fails for some reason
*
* @generatedBy CodePro at 7/7/13 10:34 PM
*/
@After
public void tearDown() throws Exception {
// Add additional tear down code here
}
/**
* Launch the test.
*
* @param args
* the command line arguments
*
* @generatedBy CodePro at 7/7/13 10:34 PM
*/
public static void main(String[] args) {
new org.junit.runner.JUnitCore().run(ServiceFacadeImplTest.class);
}
/**
* @return the serviceFacadeImpl
*/
public ServiceFacadeImpl getServiceFacadeImpl() {
return serviceFacadeImpl;
}
/**
* @param serviceFacadeImpl
* the serviceFacadeImpl to set
*/
public void setServiceFacadeImpl(ServiceFacadeImpl serviceFacadeImpl) {
this.serviceFacadeImpl = serviceFacadeImpl;
}
}
公共类ServiceFacadeImplTest{
私人服务facadeinpl服务facadeinpl;
ServiceFacadeImpl fixture=null;
/**
*运行ServiceVO getService(int)方法测试。
*
*@抛出异常
*
*@CodePro于2013年7月7日10:34生成
*/
@试验
public void testGetService_1()引发异常{
列表结果=fixture.getServices();
int serviceId=0;
ServiceVO result1=fixture.getService(1);
assertNotNull(结果1);
}
/**
*运行List getServices()方法测试。
*
*@抛出异常
*
*@CodePro于2013年7月7日10:34生成
*/
@试验
public void testGetServices_1()引发异常{
列表结果=fixture.getServices();
assertNotNull(结果);
}
/**
*执行测试前初始化。
*
*@抛出异常
*如果由于某种原因初始化失败
*
*@CodePro于2013年7月7日10:34生成
*/
@抑制警告(“资源”)
@以前
public void setUp()引发异常{
此.setServiceFacadeImpl((ServiceFacadeImpl)新类路径XmlApplicationContext(
“applicationContext facade.xml”).getBean(“serviceFacade”);
fixture=this.getServiceFacadeImpl();
}
/**
*执行测试后清理。
*
*@抛出异常
*如果由于某种原因清理失败
*
*@CodePro于2013年7月7日10:34生成
*/
@之后
public void tearDown()引发异常{
//在这里添加额外的拆卸代码
}
/**
*启动测试。
*
*@param args
*命令行参数
*
*@CodePro于2013年7月7日10:34生成
*/
公共静态void main(字符串[]args){
新建org.junit.runner.JUnitCore().run(servicefacadeimplatest.class);
}
/**
*@返回serviceFacadeImpl
*/
公共服务FacadeImpl getServiceFacadeImpl(){
返回serviceFacadeImpl;
}
/**
*@param serviceFacadeImpl
*要设置的serviceFacadeImpl
*/
公共无效设置ServiceFacadeImpl(ServiceFacadeImpl ServiceFacadeImpl){
this.servicefacdeimpl=servicefacdeimpl;
}
}
在setup()方法中,我们必须加载spring配置xml,上面我加载的是applicationContext facade.xml这是否意味着CodePro将只创建测试用例的虚拟/骨架?而不仅仅是骨架,它将根据配置为单个方法生成测试用例的数量。但是你必须做一些输入修改工作。如果我们使用CodePro,我们只需要提供输入,而不是编写整个Junit testclass。
根据配置,它将生成测试用例的数量
,您指的是spring配置
?但正如您所说,只有在生成junits之后才能给出。不,这将在eclipse code pro插件属性中配置。现在我在office中,Once reach home将为您提供示例