3

jUnit を生成するためにCodePro analytixを評価しています。spring3.0 で Web プロジェクトに取り組んでいます。現在、CodePro は役に立たない jUnit を生成しています。同一のテストケースを生成します。(マニュアルが示唆するように、すでに spring-test.jar を指定しています)。

Spring プロジェクトでこのツールを jUnit 生成に使用したことがある場合は、助けてください。spring-configurationxml をどこかに指定するか、またはDIについて知る方法を指定する必要があると思います。また、必要なオブジェクトのいくつかをモックする必要があるかもしれませんが、確かではありません。

4

1 に答える 1

2

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

* 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 config xml をロードする必要があります。上記のものは、applicationContext-facade.xml をロードしました。

于 2013-12-03T12:08:07.913 に答える