Skip to main content

What is Symflower?

Symflower is a code generation tool for Java that aims to reduce the routine efforts of unit and integration testing, so you have more time for problem-solving.

Symflower is available in the following environments:

  • Android Studio
  • CLI
  • IntelliJ
  • VS Code

Generate Test Template

Test templates provide you with all the boilerplate code that typically needs to be typed manually. Leaving you in charge to define the actual values for testing.

When using Symflower for the following method:

public class Triangle {
...

public boolean isValid() {
// Each side needs to be greater than 0
if (this.sideA <= 0 || this.sideB <= 0 || this.sideC <= 0) {
return false;
}

// Two sides need to be bigger than the third
if (this.sideA + this.sideB < sideC ||
this.sideB + this.sideC < this.sideA ||
this.sideA + this.sideC < this.sideB) {
return false;
}

return true;
}
}

Then a generated test template looks as follows:

    @Test
public void isValid() {
Triangle t = null;
boolean expected = false;
boolean actual = t.isValid();

assertEquals(expected, actual);
}
Initializers

Note that initializers will be added in one of our upcoming releases. So the above code would state new Triangle() instead of null.

Application Frameworks

Symflower supports Spring Boot offering more boilerplate code specific to Spring Boot tests.

Generate Test Suite

Symflower aims to generate high coverage test suites by applying Symbolic Execution, to determine all relevant test scenarios.

For the following getType method of 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.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

Currently external dependencies as well as the standard library are not fully analyzed by Symflower, as a result the tool may not produce complete test suites for methods relying on either of them.

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

    @Test
public void getTypeWithExternalDependency() {
Triangle t = null; // TODO This is a fallback value due to incomplete analysis.
AbstractMethodError e = null; // TODO This is a fallback value due to incomplete analysis.
int expected = 0; // TODO This is a fallback value due to incomplete analysis.
int actual = t.getTypeWithExternalDependency(e);

assertEquals(expected, actual);
}

Test-backed Diagnostics

Whenever Symflower discovers uncaught runtime exceptions, these exceptions are highlighted in your IDE. Note, that for each of these found exceptions a test case is provided that can be used to reproduce and fix the found problem.

Diagnostics for found NullPointerException.&quot;