Annotation Interface Z2UnitTest
Configuration for a unit test class that is run with the z2unit test runner. Use like this:
@RunWith(Z2UnitTestRunner.class) @Z2UnitTest(componentName="myproject/java") public class SomeTests { @Test public void testThis() throws Exception { // some test code } }
You may specify custom JUnit unit test runners. For example, a groovy written test using the Spock test specification framework would look like this:
@RunWith(Z2UnitTestRunner.class) @Z2UnitTest(componentName="spock_tests", runWith=Sputnik.class) class HelloSpockZ2 extends Specification { def "my first test"() { setup: def x = new ArrayList(); when: x.add("Hello") then: x.size() == 1 } }
Here the module name is spock_tests and specifying this as component name is a short hand for spock_tests/java. Furthermore note that Sputnik is the Spock-supplied JUnit test runner. Please check the wiki for more information on how to run Groovy on Z2.
Sometimes it can be handy to initialize other components before running a test (e.g. a Spring application
context). Instead of using a super class to do static initialization, you can instead use the dependencies()
attribute to specify Z2 components to be prepared before the test run. For example a test that requires a Spring application
context to be initialized and makes use of Spring configuration could look like this:
@RunWith(Z2UnitTestRunner.class) @Z2UnitTest( componentName="com.acme.modulex/java", dependencies={"com.acme.modulex/applicationContext"} ) @Configurable public class BusinessTests { @Autowired private SomeService someService; @Test @Transactional public void testSomething() { // ... } }
- See Also:
Z2UnitTestRunner
-
Optional Element Summary
Modifier and TypeOptional ElementDescriptionName of the test class.Name of the java component that contains the test class.A z2unit configuration file.String[]
Runtime dependencies specified as component names.Class<? extends org.junit.runner.Runner>
A Unit Test Runner to be used when executing the unit test in the target environment.Password name to send for authentication.URL to send the test request to.Username to send for authentication.
-
Element Details
-
runWith
Class<? extends org.junit.runner.Runner> runWithA Unit Test Runner to be used when executing the unit test in the target environment. That is, assuming that the unit test would be annotated as
when run outside of z2 Unit, then, in order to run the unit test with the z2 Environment, but using the runner@RunWith(MyRunner.class)
MyRunner
, the specification of the runner is added to this annotation as
In other words: By adding the runner to a declaration of this annotation, you can force a non-default test runner. This is particularly useful when running tests using JUnit extensions like the Groovy-based Spock toolkit. In that case for example, you would use the Sputnik JUnit Runner of the Spock framework.@Z2UnitTest(runWidth=MyRunner.class)
- Default:
- org.junit.runner.Runner.class
-
componentName
String componentNameName of the java component that contains the test class. A short form may be used for java components ending with "/java". Alternatively the component name may be specified using the system propertyz2unit.componentName
- Returns:
- Default:
- ""
-
className
String classNameName of the test class. Defaults to the current class name. It is however possible to specify a different test class name to be used server-side. As a result, z2Unit will report test execution events on that class which may not match the structure of the client side class. Alternatively the class name may be specified using the system propertyz2unit.className
- Returns:
- Default:
- ""
-
z2unitUrl
String z2unitUrlURL to send the test request to. Defaults tohttp://localhost:8080/z2unit/run
. The URL may alternatively be defined by the system propertyz2unit.z2unitUrl
.- Returns:
- Default:
- ""
-
z2unitUser
String z2unitUserUsername to send for authentication. Defaults to "z*". The username may alternatively be defined by the system propertyz2unit.z2unitUser
.- Returns:
- Default:
- "z*"
-
z2unitPassword
String z2unitPasswordPassword name to send for authentication. Defaults to "z". The password may alternatively be defined by the system propertyz2unit.z2unitPassword
.- Default:
- "z"
-
configFile
String configFileA z2unit configuration file. Defaults toz2unit.properties
. When found on the classpath, the properties specified in that file will be loaded into the client-side system properties.- Returns:
- Default:
- ""
-
dependencies
String[] dependenciesRuntime dependencies specified as component names. Before executing a test on the z2 side, these components will be looked up asIDependencyComponent
and, if successful, be asked toIDependencyComponent.prepare()
.- Default:
- {}
-