gpt4 book ai didi

spring - 如何将 CodePro Analytix 与 Spring MVC 项目一起使用来生成 jUnit?

转载 作者:行者123 更新时间:2023-12-02 08:50:12 26 4
gpt4 key购买 nike

我们正在评估CodePro analytix生成 jUnit。我们正在做一个spring3.0的web项目。截至目前,CodePro 正在生成无用的 jUnit。它生成相同的测试用例。 (我已经按照手册的建议指定了 spring-test.jar )。

如果您在Spring项目中使用过这个工具来生成jUnit,那么请帮忙。我假设我们必须在某处指定 spring-configuration xml,否则它将如何了解DI。另外,我们可能需要模拟一些所需的对象,但不确定。

最佳答案

完成 codepro 插件设置后,右键单击类或包 -> 选择生成 Junit 测试用例。

它将为您的类(class)生成测试类。然后在设置方法中你必须设置 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;
}
}

*Codepro 生成的类 *

ServiceFacadeImplTest.java:

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;
}
}

在setup()方法中,我们必须加载spring配置xml,上面我已经加载了applicationContext-facade.xml

关于spring - 如何将 CodePro Analytix 与 Spring MVC 项目一起使用来生成 jUnit?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20325909/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com