Skip to main content

Test suite generation

Generate Test Suite (BETA)

Symflower can generate high-coverage test suites for your code, applying Symbolic Execution to determine all relevant test scenarios. This generates both the boilerplate and the actual input values.

Example: Generating a test suite with Symflower

For the following getType method of the class Triangle, Symflower will generate a complete test set:

public class Triangle {
...

public TriangleType getType() {
if (!isValid()) {
return TriangleType.invalid;
}

if (this.sideA == this.sideB && this.sideB == this.sideC) {
return TriangleType.equilateral;
}

if (this.sideA == this.sideB || this.sideB == this.sideC ||
this.sideA == this.sideC) {
return TriangleType.isosceles;
}

return TriangleType.scalene;
}
}

Find below an excerpt of the generated test cases:

package com.symflower.demo.triangle;

import org.junit.*;
import static org.junit.Assert.*;

public class TriangleSymflowerTest {
@Test
public void getType1() {
Triangle t = new Triangle(0, 0, 0);
TriangleType expected = TriangleType.invalid;
TriangleType actual = t.getType();

assertEquals(expected, actual);
}

@Test
public void getType2() {
Triangle t = new Triangle(1, 0, 0);
TriangleType expected = TriangleType.invalid;
TriangleType actual = t.getType();

assertEquals(expected, actual);
}

@Test
public void getType3() {
Triangle t = new Triangle(1, 1, 0);
TriangleType expected = TriangleType.invalid;
TriangleType actual = t.getType();

assertEquals(expected, actual);
}

@Test
public void getType4() {
Triangle t = new Triangle(1, 1, 1);
TriangleType expected = TriangleType.equilateral;
TriangleType actual = t.getType();

assertEquals(expected, actual);
}
...
}
package com.symflower.demo.triangle;

import org.junit.jupiter.api.*;
import static org.junit.jupiter.api.Assertions.*;

public class TriangleSymflowerTest {
@Test
public void getType1() {
Triangle t = new Triangle(0, 0, 0);
TriangleType expected = TriangleType.invalid;
TriangleType actual = t.getType();

assertEquals(expected, actual);
}

@Test
public void getType2() {
Triangle t = new Triangle(1, 1, 1);
TriangleType expected = TriangleType.equilateral;
TriangleType actual = t.getType();

assertEquals(expected, actual);
}

@Test
public void getType3() {
Triangle t = new Triangle(2, 1, 1);
TriangleType expected = TriangleType.isosceles;
TriangleType actual = t.getType();

assertEquals(expected, actual);
}

@Test
public void getType4() {
Triangle t = new Triangle(8191, 8190, 1);
TriangleType expected = TriangleType.scalene;
TriangleType actual = t.getType();

assertEquals(expected, actual);
}

...
}
Limitations

Note that Symflower doesn't currently support external dependencies or the standard library. The tool may not produce complete test suites for methods relying on either of these.

In cases like these Symflower still produces a test template along the following lines:

    @Test
public void getTypeWithExternalDependency() throws AbstractMethodError {
Triangle t = new Triangle(123, 123, 123);
TriangleType expected = TriangleType.equilateral;
TriangleType actual = t.getTypeWithExternalDependency();

assertEquals(expected, actual);
}

Using Symflower's test suite generation: