JUnit Module Test

For how to use the wizard, refer to the New JUnit Module Test page.

1. JUnit Test Code

The code generated by the New JUnit module test wizard is as follows.

A method with the @Test annotation is a test method that can test an individual method. As many test methods as the number of methods selected in the wizard are generated.

The remaining methods are those that are executed before/after the test, or when an error occurs.

The generated code may differ depending on the project environment.

@DisplayName("'Bean example' test")
public class TestMyBean
extends JUnitModuleTestSupport<DefaultSystemHeader>
{

    /**
     * {@link test.bxm.bean.MyBean#getUserList(
        * BigDecimal
     * )}
     */
    @DisplayName("testGetUserList")
    @Test
    void testGetUserList()
    {
        // TODO Set required header values
        setHeaderValue("recvSvcC", "SBXM0001A001"); /*Received service code*/
        setHeaderValue("rqstRespG", "S"); /*Request response classification*/

        // List of input parameter types for the method to be tested
        Class<?>[] paramTypes= new Class<?>[] {
            BigDecimal.class
        };

        // TODO Input value setting
        BigDecimal param0= new BigDecimal("0");

        try{
            // TODO Set Expected Value: Set the expected value of the test result.
            List<DbioOutput> expected= null;

            // Perform test
            ModuleTestResult<DefaultSystemHeader, List<DbioOutput>> result=
                    doTest(
                            MyBean.class
                            , "getUserList"
                            , paramTypes
                            // ↓↓↓↓Input↓↓↓↓
                            , param0
                            );

            List<DbioOutput> actual= result.getResult();

            // Result output
            logger.debug("Output = {}", actual);

            // Compare results
            assertEquals(expected, actual);
        }
        catch (Exception e) {
            // Failed test
            logger.error(e.getMessage());
            fail(e.getMessage());
        }
    }

    @Override
    protected String getDefaultEndpointURL() {
        return "http://yourIP:yourPort/serviceEndpoint/httpService/request.obj";
    }

    @Override
    protected void beforeTest(
            URL endpointURL
            , DefaultSystemHeader requestHeader
            , IOmmObject requestOptionHeader1
            , IOmmObject requestOptionHeader2
            , IOmmObject requestOptionHeader3
            , Object[] requestInput
            )
    {
        // TODO Describe what you want to do before testing.
    }

    @Override
    protected void afterTest(
            ModuleTestResult<DefaultSystemHeader, Object> testResult
            )
    {
        // TODO If the test is successful, describe what you want to do.
    }

    @Override
    protected void catchMalformedEndpointURLError(
        String endpointURL
        , Throwable e
        )
    {
        // TODO Describe what to do when a malformed URL is used.
    }

    @Override
    protected void catchInvalidEndpointURLError(
        URL endpointURL
        )
    {
        // TODO Describe what to do when the wrong URL or data can not be read from the remote location.
    }

    @Override
    protected void catchPlatformError(
            DefaultSystemHeader requestHeader
            , IOmmObject requestOptionHeader1
            , IOmmObject requestOptionHeader2
            , IOmmObject requestOptionHeader3
            , Object[] requestInput
            , DefaultSystemHeader responseHeader
            )
    {
        // TODO Describe what to do when a platform error occurs.
    }

    @Override
    protected void catchModuleError(
            DefaultSystemHeader requestHeader
            , IOmmObject requestOptionHeader1
            , IOmmObject requestOptionHeader2
            , IOmmObject requestOptionHeader3
            , Object[] requestInput
            , DefaultSystemHeader responseHeader
            )
    {
        // TODO Describe the action to take when a module error occurs.
    }

    @Override
    protected void catchUnknownError(
            DefaultSystemHeader requestHeader
            , IOmmObject requestOptionHeader1
            , IOmmObject requestOptionHeader2
            , IOmmObject requestOptionHeader3
            , Object[] requestInput
            , Throwable cause
            )
    {
        // TODO Describe what to do when an unknown error occurs.
    }

    @Override
    protected Class<DefaultSystemHeader> getHeaderClass() {
        // TODO Auto-generated method stub
        return DefaultSystemHeader.class;
    }
}

2. Executing Tests

You can test the written test code using JUnit Test.

junitModuleTester04

  1. Right-click the source code → Run AS → select 'JUnit Test'.

    When the test is executed, you can check the result as shown in the figure below.

    junitModuleTester05

SWLab Bankware Global
  • 전체
  • BXM
  • BXCM
  • BXCP
  • BXI
제품 선택 시 더 정확한 매뉴얼 가이드를 제공해드립니다.

Copyright© Bankwareglobal All Rights Reserved.