Hi folks;
Because we have some problems with our test framework regarding writing new
tests for OWB, I have written a simple test framework for writing new tests
easily.
In this respect, I have implemented several classes:
1* OpenWebBeansTestLifecycle
This is the simulated test container. For each test method, you "start" the
container at the beginning of the test method and "shutdown" it at the end.
Therefore, you can get all the things tha are normally occurred in real
containers.
2* OpenWebBeansTestDiscoveryService
This is a class/xml scanner for artifacts that are used by the test method.
Actually, it is internally used by the "OpenWebBeansTestLifecycle".
3* AbstractUnitTest
This is the base class for all of our new tests.
Moreover, I have created a new package with name "newtests" and its subpackages
to add our new test classes. Old tests are remained in the "test" package. New
tests will be gone to "newtests" package and its reasonable child packages.
Name of the each child package shows what test classes could be gone into it.
For XML files, I have also created a new package "newtests" in the
"src/test/resources" folder. Those folders mimic the test source folder package
structure so we can easily find XML files related with test deployment. Also
XML file name must be same with the test class name.
For example,
newtests/interceptors/lifecycle/ --> contains interceptor lifecycle related
test artifacts.
newtests/interceptors/lifecycle/LifecyceTest.xml --> its deployment metadata.
Its name is the same with the test class name.
Example :
---------------------------
You can look at an example to gather some thoughts about our new framework. It
is located in the "newtests/interceptors/lifecycle/" package.
In this package you will see a test class LifecycleTest. Basically it works as
follows;
class LifecycleTest extends AbstractUnitTest
{
@Test
public void testLifecycle()
{
//Adding depoyment XML files for this test method
Collection<URL> beanXmls = new ArrayList<URL>();
beanXmls.add(getXMLUrl(PACKAGE_NAME, "LifecycleTest"));
//Adding deployment classes for this test method
Collection<Class<?>> beanClasses = new ArrayList<Class<?>>();
beanClasses.add(LifecycleInterceptor.class);
beanClasses.add(LifecycleBean.class);
//Start container
startContainer(beanClasses, beanXmls);
//DO ANYTHING YOU WANT FOR YOUR TEST
//Shutdown container
shutDownContainer();
}
}
That is all!
Thanks;
--Gurkan