Generating test suites
Generate test suite
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 test suites 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;
}
}
Here's 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);
}
...
}
See our tutorials for more code examples of using Symflower in action:
📄️ Tutorial: Generate test suite
This feature tutorial explains how to use Symflower's test suite generation feature in practice.
📄️ Tutorial: Generate LLM test suite for function
Generating test suites for a function via LLM with Symflower: tutorial with code example.
Options for generating test suites
LLM: Test generation
Enable LLM-based test generation. This feature provides access to LLM-generated test suites in your IDE. Rather than Symflower's symbolic execution engine, this feature runs your query through the LLM specified in the configuration.
You'll need to enter your chosen LLM provider's:
- URL: An OpenAPI-compatible endpoint. Example:
https://api.openai.com/v1
for GPT. The default setting is OpenRouter:https://openrouter.ai/api/v1
. - API token: The token for the model provider's API.
- Model: The model to be used for LLM queries. Example:
mistralai/codestral-mamba
.
The LLM's output (generated tests) are added to a virtual file. Copy and paste the desired code to your test file.
Data privacy
Symflower's Test Generation via LLM feature forwards your code to the configured LLM's provider. The request is sent to the LLM and the response is written into a virtual file. Symflower does not use or store your data. Read the data policy of your selected LLM provider to understand how your data is used.
Testing framework
Symflower lets you generate tests using JUnit 4 or JUnit 5. To have Symflower detect and set the framework automatically, set Java testing framework selection to automatic. The default is automatic
.
Memory limit
You can specify a maximum memory usage for Symflower. In case the memory usage exceeds the user-defined limit (specified in MB), Symflower stops the analysis. Zero means no limit. The default is
.On save
Enable unit test generation upon saving a file to streamline your workflow. The setting is off by default. Enable it to trigger test suite generation in the background every time the file is saved. Note that the test file will not be opened automatically.
Solver timeout
Set a timeout (defined in seconds) to specify a maximum for how long each solver call can run during test input generation. The default is
seconds.Style
Set Symflower to generate tests in either of the two available styles: basic or table-driven (default).
Timeout
Set a timeout (defined in seconds) to specify a maximum for how long test input generation for a single function can run. The default is
seconds.Using generated tests
Learn about managing tests with Symflower.
After generating tests, continue by reviewing the generated test cases, adding selected ones to your test file, and running the tests. To save test execution time, use test impact analysis with Symflower test-runner.