Approach to Integration Testing in D

Vijay Nayar madric at gmail.com
Fri Feb 4 12:38:08 UTC 2022


Greetings everyone,

## Question

What is your approach to integration testing in D? Do you use 
`unittest` blocks? Do you write stand-alone programs that 
interact with a running version of your program? Is there a 
library that makes certain kinds of testing easier?

For example, if I have a D project based on vibe.d, and I have 
custom converters to receive REST API request bodies in different 
formats based on the "Content-Type" HTTP header and other 
converter for the response based on the "Accepts" header, what is 
the best approach to test the entire program end-to-end?

## Context

Having done considerable work in Java using Spring and Spring 
Boot, it's very common to have [integration 
tests](https://softwaretestingfundamentals.com/integration-testing/), which the Spring Boot framework makes quite easy to set up with annotations like [@SpringBootTest](https://www.baeldung.com/spring-boot-testing#integration-testing-with-springboottest).

In a nutshell, Spring Boot is built on top of dependency 
injection, with a "Context" acting as a container for all the 
objects (called Beans) that are created and injected into that 
container. `@SpringBootTest` lets the user pick and choose which 
objects will be created for the test, and then when the program 
is run, only those objects are loaded. This allows one to do 
things like, start a complete web server environment, test by 
sending a request to some endpoint, and then validate that the 
response is what you would expect. This is especially helpful to 
validate that you are using the Spring Framework correctly, e.g. 
that custom converters you created that allow messages to be 
received in binary 
[protobuf](https://developers.google.com/protocol-buffers/) 
format instead of JSON work correctly.


More information about the Digitalmars-d-learn mailing list