Skip to end of metadata
Go to start of metadata

Jaskell has a JUnit integration package, with which one can write unit test cases within jaskell script.

Unit test written in Jaskell

In order to write a unit test case, one simply write a script file as:

"test1.jsl"
  • Similar to JUnit, one writes test cases by naming the members as "textXXX".
  • all the JUnit assert functions are supported. Parameters need to be passed by name though. ("expected", "actual", "message", "catch" etc.)
  • assertError is supported which is a handy tool to say "I expect an exception to be thrown here". The optional catch parameter allows further validation on the exception object.
  • The "assert" functions, when succeeded, return the object that's asserted.
  • fail function accepts one and only one parameter: the error message. Passing null to it invokes the "Assert.fail()" method.
  • In order to name the test case, implement the "name" member.
  • "setUp" and "tearDown" can also be implemented to provide initialization and cleanup.

For detailed description about the assert functions, please refer to Jaskell Function Library.

easier asserts

Unlike Java, the assertEquals and assertNotEquals functions compare array and collection objects by contents. Therefore, you can verify contents of an array or list by writing code like this:

java.util.Map is also compared by content. The following code validates the content of a java.util.Map object returned from a method:

Run unit test written in Jaskell

In order to run test cases written in a jaskell script file, one can use the AssertionSupport class to create a Test object:

RunTest.java
Labels: