首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >如何在Spring项目中使用CodePro分析生成jUnit?

如何在Spring项目中使用CodePro分析生成jUnit?
EN

Stack Overflow用户
提问于 2013-12-02 10:23:22
回答 1查看 2.7K关注 0票数 3

我们正在评估CodePro分析以生成jUnits。我们正在进行一个春季3.0的网络项目。到目前为止,CodePro正在生成无用的jUnits。它产生了相同的测试案例。(如手册所示,我已经指定了Springtest.jar )。

如果您在Spring项目中使用过此工具生成jUnit,那么请提供帮助。我认为我们必须在某个地方指定我们的spring-configuration xml,否则它将如何了解DI。另外,我们可能需要模拟几个所需的对象,但不确定。

EN

回答 1

Stack Overflow用户

发布于 2013-12-03 12:08:07

一旦完成了codepro插件的设置,右键单击类或包->select生成的Junit测试用例。

它将为您的类生成测试类。然后,在安装方法中,您必须设置spring配置XML。

ServiceFacadeImpl.Java:

代码语言:javascript
复制
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:

代码语言:javascript
复制
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;
    }
}

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

票数 2
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/20325909

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档