LLM-Powered Unit Testing Features for Flutter.

Samyak Jain
CommandDash
Published in
3 min readSep 20, 2023

--

LLMs like ChatGPT have impacted the way we build software today. They help auto-complete code, query large code bases, learn faster and write quality code without spending countless hours on tests.

We at Welltested AI, have been pioneering how developers write unit tests, specifically for mobile frameworks like Flutter where LLMs are constrained by insufficient knowledge of unit testing and deprecated memory of libraries and dependencies.

Demo of Welltested AI generating Unit Tests.

Our unit testing autopilot is live for Flutter and is currently being used by hundreds of developers to generate unit tests within minutes.

In our pursuit to make test coverage a default, we’re excited to announce a major release adding three new features, making it easier to write quality well-tested code.

Introducing AI-First Assist Features for Unit Testing

1. Check Testability

For anyone attempting to add unit tests for the first time, it is a sudden realisation that all code is not testable. There are testability guidelines that have to be followed while writing code, for instance:

1. Code should use dependency injection

2. Code is modular with single-purpose functions.

3. SOLID principles applied.

4. Static methods and global variables are avoided.

5. UI and logic are separated.

However, for many of us just getting started with testing, these principles might not be apparent. This is where check testability comes in.

Check Testability on `fetchProducts`

By running the command welltested generate unit --testability, check testability can exactly tell us the testability gaps in our code and how to fix them.

This also helps us learn the testability principles on the go and apply them as we write new code.

2. Generate Cases

Coming up with a list of sensible cases that each function should be tested on can get exhausting. Thanks to the AI age we live in, we can offload this part of the process to welltested too!

Generated test cases for `fetchProducts`

With welltested, we use the command welltested generate unit --cases to generate intelligent cases for any existing function in our code. We may also then review and edit the cases to fit perfectly with our requirements.

3. Dry Runs

Dry Runs are an easy way to get indicative feedback if our code works before we add actual tests by running the command welltested generate unit --dry-run.

Developers can leverage this to continuously evaluate functions on a set of test cases as we build and make changes and then solidify the features by generating real unit tests.

We’re thrilled to share with the community these new features currently available as a preview release on pub.dev. Experience the welltested magic! Links attached.

--

--

Samyak Jain
CommandDash

Building for Flutter | Helping devs build welltested apps