public abstract class AbstractJUnitTest
extends java.lang.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 Summary
Fields
Modifier and Type |
Field |
Description |
static Logger |
logger |
Test logger variable.
|
SvcDef |
svcDef |
Service definition.
|
java.util.Map |
testParams |
Test parameters.
|
Constructor Summary
Constructors
Constructor |
Description |
AbstractJUnitTest() |
|
Method Summary
All Methods Instance Methods Concrete Methods
Modifier and Type |
Method |
Description |
void |
cleanup() |
Perform test cleanup.
|
void |
invoke(SvcDef svcDef,
java.util.Map testParams)
|
Invoke all unit test methods (annotated with Test ) in the
class.
|
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString,
wait, wait, wait
Field Detail
logger
public static Logger logger
Test logger variable.
testParams
public java.util.Map testParams
Test parameters.
svcDef
public SvcDef svcDef
Service definition.
Constructor Detail
AbstractJUnitTest
public AbstractJUnitTest()
Method Detail
invoke
public void invoke(SvcDef svcDef,
java.util.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