“Can I Use Diffblue Cover and AI for Code to Write Tests in Test Driven Development (TDD)?”
Here at Diffblue, this is one of the most common questions we get asked when demonstrating what our technology does—in particular Diffblue Cover (our developer support product that writes unit tests from your code using artificial intelligence, aka ‘AI for Code’). It’s such a valuable question that we’ve broken it down into this post to discuss the topic in more detail.
A few reasons we get asked this question:
- Developers are very sensitive about altering and potentially disrupting their TDD process. Some developers are almost religious about it.
- Managers suspect that using Diffblue Cover will make their developers lazy in TDD, which will negate the benefits of doing TDD and likely the big training, cultural and process changes they’ve already undertaken to move to TDD.
- At Diffblue, we get interest in using Diffblue Cover for both active development (using a variety of methodologies) as well as inactive/legacy/maintenance development. A lot of our customers choose to start with legacy applications as the return on investment (ROI) is often easy to anticipate and definitely faster - but this doesn’t mean Diffblue Cover doesn’t work in active development with TDD!
A little about Test Driven Development (TDD)
In TDD, the test suite is written before the code. In short development cycles, code is written to pass discrete tests. Simply put:
- Use TDD now = you will have cost now
- Don’t use TDD now = you will have cost in the future
A little about Diffblue Cover
Diffblue Cover is a tool that creates unit tests. It analyzes Java code and writes a regression suite of unit tests automatically using pioneering artificial intelligence.
Connecting Diffblue Cover and TDD
Back to the initial question asked - “Can you use Diffblue Cover in a TDD environment?”
The answer? Absolutely!
Diffblue Cover supplements the cases you write, increasing the quality and reducing development time.
When we speak with companies that are mature using TDD, we regularly hear that the promise of code that is easier to maintain and refactor is not realized. This is typically because the level of testing being done is not sufficient. Maybe the developer only thought about the sunny day scenarios when producing the test cases. Or maybe the code was hard to test, therefore the developer didn’t put the effort in. Maybe the developer simply didn’t think about what the user was going to do. Whatever the reason, typically we see that developers have not overcome the initial cost required to get the return.
Using Diffblue Cover in a TDD environment
Given the challenges of TDD, let’s see how Diffblue Cover can help. Early in the development cycle, Diffblue Cover can produce template test cases given as little as the function signature. These test cases will contain everything needed to make the test compile, run and pass. If a complex mocking environment is required, it will also provide this. This allows you to focus on creating a first-class test suite through careful consideration of what is being tested, rather than spending all your time focusing on how it is being tested.
As you prepare to merge your code, Diffblue Cover can also be used as a check and balance. By running a differential analysis, you can analyze the new code changes and get only the test cases relevant to these changes. As the test cases demonstrate untested behaviors of the system, you review them. Ask yourself, is this is a genuine behavior of my code? Is it desirable or is it a bug? By doing this we are shifting left finding bugs, which of course reduces the cost of fixing. This helps Diffblue Cover and our customers who use it to capitalize on the intended benefits of TDD.
By using Diffblue Cover within a TDD environment, developers can reduce the time spent developing test suites by using tests that have been written by AI for code. Developers can also increase the quality of their code by left shifting the bug finding (and fixing) through review of changed behaviors in newly written test cases.
There you have it. Yes, Diffblue Cover can be used in a TDD environment.
Any questions? Reach out to learn more.