Approach to Integration Testing in D

Vijay Nayar madric at gmail.com
Sun Feb 6 20:15:06 UTC 2022


On Sunday, 6 February 2022 at 17:36:05 UTC, Vijay Nayar wrote:
> On Friday, 4 February 2022 at 17:39:00 UTC, H. S. Teoh wrote:
>> On Fri, Feb 04, 2022 at 12:38:08PM +0000, Vijay Nayar via

When working on a dub configuration needed to separately run 
integration tests that operate on the fully built program from 
the outside, treating it like a black-box, I had run into a 
number of problems because `dub` implicitly created 
configurations called `application` or `library` only if you have 
no configurations of your own defined. But as soon as I added my 
own configuration, those default configurations were no longer 
being created and I suddenly found myself seeing strange errors 
when trying to run unit-tests or builds.

See [GitHub Dub Issue 
#1270](https://github.com/dlang/dub/issues/1270).

However, I did finally navigate the tricky waters and make a 
configuration that does actually work for `dub build`, `dub test` 
and `dub test --config=integration`.

I thought I would share what I found here:

```sdl
authors "Vijay Nayar"
copyright "Copyright © 2019, Vijay Nayar"
description "Receives data from sources, converts it to 
protobufs, and delivers it in batches to stem."
license "proprietary"
name "mouth"
targetPath "target"

# By default, 'dub' creates either an 'application' or 'library' 
config if no
# configuration exists.
# Because we need a configuration for integration tests, this 
forces us
# to create the 'application' config as well.
#
# The 'dub test' command searches for the first 'library' target 
type, and
# if none exists, the first 'executable'.

# Used by 'dub build' and 'dub test'.
configuration "application" {
   targetName "mouth"
   targetType "executable"
   dependency "funnel:common" path="../"
   dependency "funnel:proto" path="../"
   dependency "nanomsg-wrapper" version="~>0.5.3"
   dependency "poodinis" version="~>8.0.3"
   dependency "vibe-d" version="~>0.9.4"
   # This must be listed so that 'dub test' knows to ignore it.
   mainSourceFile "source/app.d"
}

# Used by 'dub test --config=integration'
configuration "integration" {
   targetName "mouth_integration"
   # This must not be 'library', or it will be used by 'dub test'.
   targetType "executable"
   # The "source/" directory is automatically included, it must be 
explicitly
   # excluded instead.
   excludedSourceFiles "source/*"
   # The integration tests' source is in './integration'.
   sourcePaths "integration"
   importPaths "integration"
   # Make sure the executable we are testing exists.
   preBuildCommands "echo IMPORT_PATHS=$$IMPORT_PATHS"
   preRunCommands "cd $PACKAGE_DIR ; dub build"
}
```


More information about the Digitalmars-d-learn mailing list