Programming Testing: Seams

From wikinotes

Seams are places where you can alter the behaviour of a program when it is under test.
The available seams depend on the programming language in use.
When designing a program for testing, you should provide seams to allow it to be tested.

PreProcessor Seams

TODO:

untested

In C/C++ and other languages with macros,
you can use an IFDEF to inject or replace test methods.

Something like this.

// main.c

#include <stdio.h>
#include "libusers.h"
#include testmacros.h  // <-- when testing, define 'create_db_user' locally

int main(int argc, char *argv[]) {
    int id = 100
    create_db_user("foo@example.com", "foo")
}
// testmacros.h

#ifdef TESTING

struct User {
    int  id;
    char *email;
    char *name;
}

User users[5] = {};

#define create_db_user(email, name) \
    { \
        struct User user; \
        user.id = 123; \
        user.email = email; \
        user.name = name; \
        users[0] = user; \
    }

#endif

Linker Seams

Package Seams

Object Seams

Interface Seams