Skip to content

Example usage of CoverageMatrix

David Tengeri edited this page Oct 26, 2015 · 1 revision

A sample test class that creates a new coverage matrix and saves it to the specified location:

import hu.sed.soda.data.CoverageMatrix;

public class TestCoverageMatrix {
    static {
        // Load the JNI wrapper library.
        System.loadLibrary("SoDAJni");
    }

    public static void main(String args[]) {
        // Create a new instance.
        CoverageMatrix matrix = new CoverageMatrix();
        // Add some tests to the matrix.
        matrix.addTestcaseName("hello1");
        matrix.addTestcaseName("hello2");
        matrix.addTestcaseName("hello3");
        // Add some methods to the matrix.
        matrix.addCodeElementName("method1");
        matrix.addCodeElementName("method2");

        // Resize the coverage bit matrix. Must be called manually because of performance.
        matrix.refitMatrixSize();

        // Set coverage data.
        matrix.setRelation("hello1", "method1", true);
        matrix.setRelation("hello3", "method1", true);
        matrix.setRelation("hello3", "method2", true);

        // Save the matrix.
        matrix.save("/tmp/testMatrix.SoDA");

       // Cleanup the memory on the native side.
        matrix.dispose();
    }
}

Compile the code

Prerequisites:

  • You have succesfully built the soda-java jar file and the corresponding jni native library.

javac -cp "/path/to/soda-java.jar:." TestCoverageMatrix.java

Run the sample

java -Djava.library.path=/path/to/the/dir/of/soda/jni/lib -cp "/path/to/soda-java.jar:." TestCoverageMatrix
Clone this wiki locally