Skip to main content

What is Symflower?

Symflower is a code generation tool for Java, Spring, and Spring Boot 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:

  • VS Code
  • IntelliJ IDEA
  • Android Studio
  • CLI

Symflower extends your favorite IDE with 3 features:

  1. Generate test template
  2. Generate test suite (BETA)
  3. Test-backed diagnostics

Generate Test Template

Symflower's test templates provide you with all the boilerplate code that you would otherwise type manually. The plugin generates the necessary imports, annotations, object initializations, function calls, asserts, and more at once, leaving you in charge of defining the actual values for testing.

Example: Generating test templates with Symflower

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;
}
}

The test template generated by Symflower looks like this:

    @Test
public void isValid() {
Triangle t = new Triangle(123, 123, 123);
boolean expected = true;
boolean actual = t.isValid();

assertEquals(expected, actual);
}
Application Frameworks

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

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.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);
}

Test-backed Diagnostics

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

Diagnostics for found NullPointerException.&quot;