Development Driven Testing (DDT) lets you generate unit tests from a running application. Reproduce a bug, generate a properly mocked test

Related tags

Web Frameworks ddtj
Overview

DDTJ: It kills bugs

Build Quality Gate Status No Known Vulnerabilities

DDT is the flip side of TDD (Test-driven development). It stands for "Development Driven Tests". Notice that it doesn’t contradict or replace test-driven development, in fact, it’s a perfect complement to it. But let’s start by defining DDT and how it improves production code and code quality.

DDT lets us generate test source code from a running application.

It’s often very difficult to create a unit test for a complex bug with complex mocking. The goal of DDT is: if you can reproduce it you can unit test it. It provides you with the full set of tools to generate a fully isolated unit test. This, in-turn enables high-quality code, reducing the programming feedback loop.

Run the app, it will auto-generate mock objects and unit test for the method of your choice!

DDT vs. DDTJ

DDT is the name of the approach (Development Driven Tests) whereas DDTJ is the specific implementation. Notice that there's no detailed specification of DDT, just the separation of terms.

What DDT Is Not

It isn’t a:

  • Replacement for test-driven development - TDD is a software development process. DDT is a tool that produces tests. These tests can join the existing tests in providing greater coverage for test-driven development
  • Replacement for integration tests/functional tests/acceptance tests/smoke tests - Integration tests are essential for a healthy project. The feedback loop with unit tests is faster, so we normally prefer them first. But they are not a replacement!
  • It isn’t a “test recorder” - well, technically it is. But not in the classical sense, since it generates unit tests and runs constantly
  • A tool for production - this tool affects performance and RAM usage. That isn’t a big deal since we’re running on a development machine. Don’t use it in production code!

There are front end test recording tools that effectively “auto-generate” integration tests. They’re great tools for user interfaces, but they aren’t always ideal for backend developers.

If you still run into issues when running manual tests, then this might be an interesting option to explore.

Status

Currently, DDTJ is under initial development and still isn't functional. Even when it will be functional, this isn't production code yet!

The current target is Java and Spring Boot. However, the code/design is generic enough to enable support for other languages/platforms. I made all design decisions with portability in mind. If you would like to use this in a different language/platform, please star the project, check the issue tracker and file an RFE though the project issue tracker if one doesn’t exist.

We’ll try to prioritize support based on GitHub voting and support.

Usage

NOTE: Currently DDTJ requires Java SE 11 or newer.

Download and unzip the DDTJ binary distribution from here (this isn't available yet). In it you will find:

  • backend.jar
  • ddtj.jar

Run:

java -jar backend.jar

Then run your application with the ddtj.jar as such:

java -jar ddtj.jar -run [-javahome:<path-to-java-home] [-whitelist:regex-whitelist classes] [-arg=<app argument>...] mainClass

Once you have enough usage of your app worthy of testing, you can start using the CLI to generate tests:

java -jar ddtj.jar -list-classes

Will print out the list of classes for which there are available unit tests. Sample output looks like:

Class Name               Methods                Total Tests
com.mycompany.MyClass     20      1000
…
java -jar ddtj.jar -list-methods <class-name>

Will print out the list of methods in the class for which there are available unit tests. Sample output looks like:

Method                Total Tests
methodSignature          1000
…
java -jar ddtj.jar -list-tests <class-name> <method-signature>

Will print out the list of methods in the class for which there are available unit tests. Sample output looks like:

Sampling Time                             Test Id
Dec 12, 2021, 10:00:00.00          37866-3333-333-3333
…
java -jar ddtj.jar -generate 37866-3333-333-3333 -type junit -package com.mycompany.myapp.tests -classname MyMethodTest -methodName testMethod

Will print out a unit test class with the junit processor:

package com.mycompany.myapp.tests;

import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest; 
import org.mockito.InjectMocks;
import org.mockito.Mock;
import org.mockito.Mockito;
import org.mockito.junit.jupiter.MockitoExtension;

@ExtendWith(MockitoExtension.class)
class MyMethodTest {
  @Mock
  private UserRepository userRepository;

  @Autowired 
  @InjectMocks
  private MyClass myClass;

  private static final List<User> listOfEntities = new ArrayList();

  @Test
  void testMethod() {
      Mockito.when(userRepository.findAll()).thenReturn(listOfEntities);
      myClass.methodSignature(5, "other string");
  }
}

Notice that the mock objects are simplistic in this piece of code and already they encapsulate most of the method.

Working with the Sources

You can follow the process in the actions script for building the project. Effectively we have three projects:

  • Common - common code, mostly data objects
  • CLI - command line tool
  • Backend - spring boot backend server

To compile everything do:

cd Common
mvn install
cd ../CLI
mvn package
cd ../Backend
mvn package

You can read about the process of building DDTJ in the following blog series: https://dev.to/codenameone/series/15971

Future Enhancements

An interesting use case is automatic test generation to increase code coverage. When running an application, we can detect code paths that weren't tested and generate unit tests to cover the writing tests gap. This would require integration with testing tools to detect current coverage information.

Currently, I designed DDTJ for use by development teams, but a feature like this might make it suitable for wider audiences. There's also a plan to create a web interface besides the CLI.

Future versions of the tools would hopefully be compiled to native code with GraalVM to reduce RAM usage and startup time. A focus of the project is on simple design to enable native compilation.

I already mentioned support for additional languages/platforms above. But we need to support additional unit testing frameworks as well. I designed the system with templating and extensible code to facilitate future growth.

Currently, the design does nothing about code duplication in newly generated tests. This is intentional, as the opposite would include a far more complex public interface to the tool. However, this is something we should reconsider, as duplication of code is a major code smell.

There's currently no support for programming teams and shared workflow. I'm not sure if there's room for something like that, but it would be interesting. Since DDT collects a lot of data about the system, it can reveal code patterns that can improve the team’s software development practice. This is vague, but possibly an even bigger feature awaits within...

You might also like...

Write JSON unit tests in less code. Great for testing REST interfaces.

JSONassert Write JSON unit tests in less code. Great for testing REST interfaces. Summary Write JSON tests as if you are comparing a string. Under the

Dec 29, 2022

The main goal of the project is to reproduce a Database for a Ecommerce Web Application;

The main goal of the project is to reproduce a Database for a Ecommerce Web Application;

Web-Ecommerce Springboot Web Application The main goal of the project is to reproduce a Database for a Ecommerce Web Application; We have a Category-P

Feb 2, 2022

A unit testing library for varying test data.

Burst A unit testing library for varying test data. DEPRECATED: Burst remains stable and functional, but you should check out TestParameterInjector fr

Oct 9, 2022

Auto-Unit-Test-Case-Generator automatically generates high-level code-coverage JUnit test suites for Java, widely used within the ANT Group.

中文README传送门 What is Auto-Unit-Test-Case-Generator Auto-Unit-Test-Case-Generator generates JUnit test suites for Java class just as its name. During te

Dec 22, 2022

Tzatziki - Decathlon library to ease and promote Test Driven Development of Java microservices!

Tzatziki Steps Library This project is a collection of ready-to-use Cucumber steps making it easy to TDD Java microservices by focusing on an outside-

Dec 15, 2022

An expressive Mock Object library for Test Driven Development

JMock Library Maven dependency groupIdorg.jmock/groupId artifactIdjmock-junit5/artifactId version2.12.0/version scope

Aug 23, 2022

MixStack lets you connects Flutter smoothly with Native pages, supports things like Multiple Tab Embeded Flutter View, Dynamic tab changing, and more. You can enjoy a smooth transition from legacy native code to Flutter with it.

MixStack lets you connects Flutter smoothly with Native pages, supports things like Multiple Tab Embeded Flutter View, Dynamic tab changing, and more. You can enjoy a smooth transition from legacy native code to Flutter with it.

中文 README MixStack MixStack lets you connects Flutter smoothly with Native pages, supports things like Multiple Tab Embeded Flutter View, Dynamic tab

Dec 19, 2022

PowerMock is a Java framework that allows you to unit test code normally regarded as untestable.

PowerMock is a Java framework that allows you to unit test code normally regarded as untestable.

Writing unit tests can be hard and sometimes good design has to be sacrificed for the sole purpose of testability. Often testability corresponds to go

Dec 28, 2022

PowerMock is a Java framework that allows you to unit test code normally regarded as untestable.

PowerMock is a Java framework that allows you to unit test code normally regarded as untestable.

Writing unit tests can be hard and sometimes good design has to be sacrificed for the sole purpose of testability. Often testability corresponds to go

Dec 28, 2022

Just-In-Time Access is an AppEngine application that lets you manage just-in-time privileged access to Google Cloud projects.

Just-In-Time Access is an AppEngine application that lets you manage just-in-time privileged access to Google Cloud projects.

Just-In-Time Access Just-In-Time Access is an AppEngine application that lets you manage just-in-time privileged access to Google Cloud projects. Syno

Jan 3, 2023

cglib - Byte Code Generation Library is high level API to generate and transform Java byte code. It is used by AOP, testing, data access frameworks to generate dynamic proxy objects and intercept field access.

cglib Byte Code Generation Library is high level API to generate and transform JAVA byte code. It is used by AOP, testing, data access frameworks to g

Jan 8, 2023

Extension module to properly support datatypes of javax.money

Jackson Datatype Money Jackson Datatype Money is a Jackson module to support JSON serialization and deserialization of JavaMoney data types. It fills

Jan 2, 2023

A fork of Cliff Click's High Scale Library. Improved with bug fixes and a real build system.

High Scale Lib This is Boundary's fork of Cliff Click's high scale lib. We will be maintaining this fork with bug fixes, improvements and versioned bu

Jan 2, 2023

Properly implements shields being able to block endcrystal blasts, as they should; like every other explosion type.

Endcrystal-Shield Properly implements shields being able to block endcrystal blasts, as they should; like every other explosion type. Mojang CONFIRMED

Jul 7, 2022

BurritoSpigot is a fork of TacoSpigot 1.8.9 that offers several enhancements to performance as well as bug fixes. while offer extra APIs and support for plugins

🌯 BurritoSpigot 🌯 BurritoSpigot is a fork of TacoSpigot 1.8.8 that offers several enhancements to performance as well as bug fixes. while offer extr

Dec 20, 2022

Captures log entries for unit testing purposes

LogCaptor Install with maven dependency groupIdio.github.hakky54/groupId artifactIdlogcaptor/artifactId version2.4.0/version

Jan 1, 2023

🎯 ConsoleCaptor captures console output for unit testing purposes

ConsoleCaptor Install library with: Install with maven dependency groupIdio.github.hakky54/groupId artifactIdconsolecaptor/artifactId

Dec 9, 2022

Java Concolic Unit Testing Engine

jCUTE The Java Concolic Unit Testing Engine (jCUTE) automatically generates unit tests for Java programs. Concolic execution combines randomized concr

Nov 7, 2022
Comments
  • Major refactor for 0.0.3

    Major refactor for 0.0.3

    Removed Snyk badge which isn't working. Moved common code that was really backend state into the backend. Created initial web interface Implemented first CLI end to end

    opened by shai-almog 4
  • Configure WhiteSource Bolt for GitHub

    Configure WhiteSource Bolt for GitHub

    Welcome to WhiteSource Bolt for GitHub! This is an onboarding PR to help you understand and configure settings before WhiteSource starts scanning your repository for security vulnerabilities.

    :vertical_traffic_light: WhiteSource Bolt for GitHub will start scanning your repository only once you merge this Pull Request. To disable WhiteSource Bolt for GitHub, simply close this Pull Request.


    What to Expect

    This PR contains a '.whitesource' configuration file which can be customized to your needs. If no changes were applied to this file, WhiteSource Bolt for GitHub will use the default configuration.

    Before merging this PR, Make sure the Issues tab is enabled. Once you merge this PR, WhiteSource Bolt for GitHub will scan your repository and create a GitHub Issue for every vulnerability detected in your repository.

    If you do not want a GitHub Issue to be created for each detected vulnerability, you can edit the '.whitesource' file and set the 'minSeverityLevel' parameter to 'NONE'.


    :question: Got questions? Check out WhiteSource Bolt for GitHub docs. If you need any further assistance then you can also request help here.

    opened by mend-bolt-for-github[bot] 1
Owner
null
A web MVC action-based framework, on top of CDI, for fast and maintainable Java development.

A web MVC action-based framework, on top of CDI, for fast and maintainable Java development. Downloading For a quick start, you can use this snippet i

Caelum 347 Nov 15, 2022
CUBA Platform is a high level framework for enterprise applications development

Java RAD framework for enterprise web applications Website | Online Demo | Documentation | Guides | Forum CUBA Platform is a high level framework for

CUBA Platform 1.3k Jan 1, 2023
Flutter GetX模板代码生成 Gradle模式开发---Used to generate the template code of GetX framework

getx_template 语言: English | 中文简体 GetX usage Gold digging: Flutter GetX use --- simple charm! Renderings Plug-in effect Take a look at the effect diagr

小呆呆666 241 Dec 23, 2022
crnk.io - Crank up the development of RESTful applications

crnk.io - Crank up the development of RESTful applications! release on jcenter latest in private repository What is Crnk? Crnk is an implementation of

null 272 Nov 28, 2022
RESTKit is a powerful toolkit for restful services development

RESTKit is a powerful toolkit for restful services development. This plugin is committed to enhancing development efficiency with useful

Mr.Hu 25 Dec 22, 2022
an awesome automation test framework

PnxTest PnxTest is a Java-based test automation framework that unites all testing layers: Mobile applications, WEB applications, REST services. Due to

nicolas chen 21 Jul 29, 2022
RESTEasy is a JBoss project that provides various frameworks to help you build RESTful Web Services and RESTful Java applications

RESTEasy RESTEasy is a JBoss.org project aimed at providing productivity frameworks for developing client and server RESTful applications and services

RESTEasy 1k Dec 23, 2022
The Grails Web Application Framework

Build Status Slack Signup Slack Signup Grails Grails is a framework used to build web applications with the Groovy programming language. The core fram

grails 2.7k Jan 5, 2023
Sidekick is a live application debugger that lets you troubleshoot your applications while they keep on running

Explore Docs » Quick Start Tutorial » Table of Contents What is Sidekick? Sidekick Actions Why Sidekick? Features Who should use Sidekick? How does Si

Sidekick 1.6k Jan 6, 2023