In this post I just want to give a basic overview of how the unit testing works. It can look very convoluted and can be really difficult to troubleshoot the first time since it may be unclear exactly how it works...
The unit tests are created in the package /core/src/test/java
In this package you will see two files created: EJB3Container.java and yourClassNameTest.java
The EJB3Container is a common EJB3 container which is set up to use JBoss 3.2.0.ga by default.
The other class is the test class specific to your service class. Andromda will generate one of these for each class annotated with the <
Additionally you will see a package /core/src/test/resources which will contain a host of configuration files with various settings that can be changed to affect your unit testing container. The first two files you will probably be concerned with are the testng.xml file and the embedded-jboss-beans.xml file.
The testng.xml file contains a list of all of the classes that testng will instantiate and inject into the unit testing container. It is important that testng be configured to use this file, otherwise the andromda test will not work.
The embedded-jboss-beans.xml file contains settings for the connection of the JBoss microcontainer to your local database (amongst other things)... make sure you have this modified appropriately to access your local environment.
The basic flow of the TestNG tests with the andromda build is as follows:
For testing within Eclipse:
TestNG Eclipse Plugin is loaded, it is pointed to the testng.xml file via the configuration screen in Eclipse. TestNG plugin loads up the EJB3Container and your Test classes.
Your test class is run. Since the EJB3Container has been previously loaded, your test classes can access the EJB local and/or remote interfaces via JDNI calls to the InitialContext.
Method calls to the EJBs are made in the test class... these get run inside of the EJB3Microcontainer, and the results are returned to the test classes and assertations can be made on them at that point.
No comments:
Post a Comment