Programming Testing: Seams

From wikinotes
Revision as of 14:03, 23 July 2022 by Will (talk | contribs) (Created page with "Seams are places where you can alter the behaviour of a program when it is under test.<br> The available seams depend on the programming language in use.<br> When designing a program for testing, you should provide seams to allow it to be tested. = PreProcessor Seams = <blockquote> {{ TODO | untested }} In C/C++ and other languages with macros,<br> you can use an <code>IFDEF</code> to inject or replace test methods. Something like this. <syntaxhighlight lang="c"> #ifd...")
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)

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.

#ifdef TESTING

struct User {
    int  id;
    char *name;
}

User users[5] = {};

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

#endif

Linker Seams

Package Seams

Object Seams

Interface Seams