JavaOnTracks: Basic Testing API
This testing API, is intended to be very lightweight and non intrusive.
You don't need to configure anything or have to change your code(implement something) to use it.
All you have to do is add a method called jotTest() to whichever class you want to run a test in, and test something in it.
The JOTTester class is there to run the tests, you can run it from a cron to test periodically, or call it from Ant.
It has options such as: create reports (text or HTML) and to send them by email (always or only on failure) etc...
Test Example
Test Example
public class YourClass
{
public String yourMethod(String arg)
{
//.... return "i worked";
}
public static void jotTest() throws Throwable
{
YouClass clazz=new YourClass();
// tag() is just to log some test progress infos in your logs
JOTTester.tag("Starting My super cool test");
// typical test: test that a function returns the expected value (if not a JOTTestException will be thrown)
JOTTester.checkIf("Testing the proper return value: ",clazz.yourMethod("").equals("i worked"));
// checking for an exception (here we want yourTest(null) throws a NullPointerException)
String[] args={null};
JOTTester.checkThrowsException(java.lang.NullPointerException.class,"yourMethod",args);
JOTTester.tag("Super cool test is done");
}
}
Running the test
To run the tests, all you have to do is invoke the "JOTTester" class.
It has quite a few options, you can run "java JOTTester" to list them (or see bellow to see the list).
Run the test from ant
Ant task to run tests
<target name="test" depends="compile">
<java classname="net.jot.testing.JOTTester">
<!-- Example classpath, adjust to your needs, or use classpath variable -->
<classpath path="classes:/usr/share/java/postgresql-jdbc3-8.1.jar"/>
<!-- First arg(required) is to your classes (to be tested) folder
<arg value="classes"/>
<!-- you can pass arguments to tell JOTTester what to do, see ""JOTTEster Arguments bellow for other args -->
<!--<arg value="-debug"/>-->
<!--<arg value="-outputTo=/tmp/jottest.html"/>-->
</java>
</target>
JOTTester arguments
Syntax: java "net.jot.testing.JOTTester classpath <options>
Where classpath is column or semiColumn. separated list of class folders (where the classes to be tested are)
- Option: -includePackages=“”
- Option: -excludePackages=“”
- Option: -debug
- Option: -stopOnFailure=
- Option: -help
- Option: -outputTo=“”
- Option: -emailAlways=“”
- Option: -emailOnFailure=“”
- Option: -selfTest
Example: java “net.jot.testing.JOTTEster "classes;c:\my_classes" -includePackages="com.mypkg.*;com.otherpkg.*” -debug=true
JavaDoc
Comments:
Add a new Comment
Back to top
