Skip to content

0.7.x manual 09.API

Hiroshi Ukai edited this page Jul 9, 2016 · 4 revisions

Background

JCUnit already has API which enables users to generate test suites programmatically, but it doesn't support some important features like FSM etc.

Design

Following is a diagram that illustrates (current) relationships between entities that you need to know to build a TestSuite object without relying on JCUnit's test runner.

   
   +-----------------+                                      +--------------------+
   | List< TestCase >|                                      |Map< String,Object >|
   +-----------------+                                      +--------------------+
            |                                                         |
            A                                                         A
            |                                                         |
   +-----------------+      +---------+       +-----------+        +-----+
   |TestSuite.Builder|- - ->|TestSuite|<>---->|TestCase   |<>----->|Tuple|
   +-----------------+      +---------+ 1   * +-----------+ 1    1 +-----+
           1|                                 |Type  type |
            |                                 +-----------+
            |
            |               +---------------------------+
            +-------------->|TestSuite.Builder.Predicate|
                          * +---------------------------+

And following is a code example to use this API.

 001: TestSuite testSuite = new TestSuite.Builder()
 002:     .addFactor("factor1", 1, 2, 3)
 003:     .addBooleanFactor("boolean")
 004:     .addByteFactor("byte")
 005:     .addCharFactor("char")
 006:     .addShortFactor("short")
 007:     .addIntFactor("int")
 008:     .addLongFactor("long")
 009:     .addFloatFactor("float")
 010:     .addDoubleFactor("double")
 011:     .addStringFactor("string")
 012:     .addEnumLevels("enum", TestCase.Type.class)
 013:     .addConstraint(new TestSuite.Builder.Predicate() {
 014:         public boolean apply(Tuple in) {
 015:             return !in.get("factor1").equals(1);
 016:     }})
 017:     .enableNegativeTests()
 018: .build();
 019:
 020: for (TestCase each : testSuite) {
 021:     ...
 022:     for (Predicate violatedConstraint : TestSuite.getViolatedConstraints(each) {
 023:         ...
 024:     }
 025: }

What we want to do for FSM is something like following.

         .addFsmFactor(
             "flyingSpaghettiMonster", 
             new Fsm.Builder()
                 .addState( ... )
             .build()
         )

Usage

(t.b.d.)

References

Clone this wiki locally