
- Introduction
- Adding JTestConnect to your project
- How to Annotate Your Classes
- Configuring JTestConnect
- Building JTestConnect from source
Configuring JTestConnect
JTestConnect uses the jtestconnect.xml configuration file specified in your Ant task to determine how the test for this method should look. Lets take another look at the one we used in our example.
<!-- Configures JTestConnect --> <jtestconnect> <defaults> <property name="package" value=""/> <property name="classPrefix" value=""/> <property name="classSuffix" value="Test"/> <property name="methodPrefix" value="test"/> <property name="methodSuffix" value=""/> </defaults> </jtestconnect>
This file defines a naming convention that describes how we name our tests. JTestConnect uses this files to generate expected test names. Let examine what each of these values actually mean:
- package - The package name that will be appended to the end of the SUTs package name to find the expected package name. In our config file we have left it blank, which means that our test class should have the same package name as our SUT. This is recommended as a best practice because it allows your test access to protected and default methods in your SUT. If we had specified "test" as the package property, we would have to put our test into the package "org.mycompany.myproject.services.test".
- classPrefix - The prefix that should be appended to your SUT class name to arrive at the test class name. In this case we append nothing (we prefer a suffix). If we had specified classPrefix to be "test" then JTestConnect expects a class with the name "TestMyService".
- classSuffix - The same as the classPrefix option, but allows a suffix to be added to the end of the test class to arrive at the test class name. In our example this is exactly what we have done. We will expect a test class with the name "MyServiceTest".
- methodPrefix - Appends a prefix to the name of the method being tested. In our example we would expect a method with name "testPerformAction".
- methodSuffix - As above, except adds a suffix to the end of the method name.
With this information, JTestConnect will determine that we need a test class called: "MyServiceTest" with a method "testPerformAction". If this method is not found in your test code, JTestConnect will complain.