Class AbstractJUnitTest


  • public abstract class AbstractJUnitTest
    extends Object

    Provides an abstraction utility for unit testing.

    Please find the junit examples below.

    JUnit Example (Multiple Tests)

    This Groovy example shows how to implement a number of unit tests in a class.

     import com.avoka.tm.svc.*
     import com.avoka.tm.test.*
     import com.avoka.tm.util.*
     import com.avoka.tm.vo.*
     import org.junit.*
    
     class MyServiceUnitTest extends AbstractJUnitTest {
    
          // Injected at runtime
          public Logger logger
    
          MockRequest request
          Txn txn
    
          @BeforeClass
          public static void setUp() {
          }
    
          @Before
          public void beforeTest() {
              request = new MockRequest()
              txn = new MockVoBuilder().createTxnOpened()
          }
    
          @Test
          public void testSvcDefNotNull() {
              assert svcDef != null
          }
    
          @Test
          public void testInvokeSvc_noRequestParams() {
    
              Map params = [
                "svcDef": svcDef,
                "txn": txn,
                "request": request,
                "user": null
              ]
    
              String result = (String) new ServiceInvoker(svcDef).invoke(params)
    
              logger.info result
    
              assert result != null
          }
    
          @Test
          public void testInvokeSvc_branch3RequestParam() {
    
              request.setParameter("branch3", "test")
    
              Map params = [
                "svcDef": svcDef,
                "txn": txn,
                "request": request,
                "user": null
              ]
    
              String result = (String) new ServiceInvoker(svcDef).invoke(params)
    
              logger.info result
    
              assert "branch3".equals(result)
          }
    
          @After
          public void afterTest() {
              txn = null
              request = null
          }
    
          @AfterClass
          public static void tearDown() {
          }
     } 
    Since:
    5.1.4
    • Field Detail

      • logger

        public static Logger logger
        Test logger variable.
      • testParams

        public Map testParams
        Test parameters.
      • svcDef

        public SvcDef svcDef
        Service definition.
    • Constructor Detail

      • AbstractJUnitTest

        public AbstractJUnitTest()
    • Method Detail

      • invoke

        public void invoke​(SvcDef svcDef,
                           Map testParams)
        Invoke all unit test methods (annotated with Test) in the class.
        Parameters:
        svcDef - service definition
        testParams - test parameters
      • cleanup

        public void cleanup()
        Perform test cleanup.
        Since:
        17.10.0