Test case selection

User defined test cases

As for the defintion of transition system, the user may either define his test cases in java (using TestSetDefinition class) or load them from an XML file (using TestCaseXmlLoader).

import be.unamur.transitionsystem.dsl.test.TestSetDefinition;
import static be.unamur.transitionsystem.dsl.test.TestCaseXmlLoader.*;
import static be.unamur.transitionsystem.dsl.test.TestCaseXmlPrinter.*;

public Main extends TestSetDefinition{
    @Override
    protected void define() {
        id("tc1").action("init")
            .action("perf1")
            .action("perf2")
            .action("close").end();
        id("tc2").action("init")
            .action("perf3")
            .action("perf4")
            .action("close").end();        
        }
    }

    public static void main(String[] args){
        TestSet set = new Main().getTestSet();
        // Print test set 
        print(set, "mytestset.xml");
        // Load from XML
        set = loadLtsTestCases("mytestset.xml");
    }
}

Random test case selection

Random class allows to randomly select test cases un a transition systel. Default maximal test case size and default number of test cases are defined by RandomTestCaseGenerator.DEFAULT_MAX_LENGTH and RandomTestCaseGenerator.DEFAULT_NUMBER_TEST_CASES, those values may be changed by giving additional parameters to the randomSelection method.

import static be.unamur.transitionsystem.dsl.selection.Random.*;

public Main{
    public static void main(String[] args){
        LabelledTransitionSystem lts = new MyLTS().getTransitionSystem();
        // Random test cases selection
        TestSet set = randomSelection(lts);
    }
}

All-actions coverage test case selction

AllActions class allows to select a set of test cases which respects the all-actions coverage criteria, i.e., when the test set is executed, all actions of the system are executed at least once.

import static be.unamur.transitionsystem.dsl.selection.AllActions.*;

public Main{
    public static void main(String[] args){
        LabelledTransitionSystem lts = new MyLTS().getTransitionSystem();
        // all-actions coverage test cases selection
        TestSet set = allActionsSelection(lts);
    }
}

Dissimilarity-based test case selection

The Dissimilar class allows to select test cases based on their dissimilarity using a seach-based (1+1) evolutionary algorithm. Use has to specify if local or global distances has to be used to prioritize the test cases, the TestCaseDissimilarityComputor to use, the maximal running time (default is DissimilarTestCaseGenerator.DEFAULT_RUNNING_TIME_MILLI), and the number of test cases to generate (default is DissimilarTestCaseGenerator.DEFAULT_NUMBER_OF_TEST_CASES).

import static be.unamur.transitionsystem.dsl.selection.Dissimilar.*;

public Main{
    public static void main(String[] args){
        LabelledTransitionSystem lts = new MyLTS().getTransitionSystem();
        // Dissimilar test cases selection
        TestSet set = from(lts) 
            .withLocalMaxDistance(jaccard()) // Specify the distance and prioritisation to use
            .during(10000L)
            .generate(20);
        // Dissimilar FTS test cases selection
        FeaturedTransitionSystem fts = new MyFts().getTransitionSystem();
        DimacsModel fd = DimacsModel.createFromDimacsFile("myfd.dimacs");
        BDDSolverFacade solver = new BDDSolverFacade(fd);
        set = from(lts) 
            .withGlobalMaxDistance(ftsDissimilarity(solver, antidice(), avg())) // Specify the distance and prioritisation to use
            .generate();
    }
}