Programming Testing: Seams: Difference between revisions
From wikinotes
Line 9: | Line 9: | ||
In C/C++ and other languages with macros,<br> | In C/C++ and other languages with macros,<br> | ||
you can use an <code> | you can use an <code>#ifdef</code> to inject or replace test methods. | ||
{{ example | |||
| | |||
| | |||
In the real file, we include <code>testmacros.h</code>,<br> | |||
which in our tests will define functions locally. | |||
<syntaxhighlight lang="c"> | <syntaxhighlight lang="c"> | ||
// main.c | // main.c | ||
Line 26: | Line 30: | ||
</syntaxhighlight> | </syntaxhighlight> | ||
In our macro, we define a function that fakes creating a user in the database. | |||
<syntaxhighlight lang="c"> | <syntaxhighlight lang="c"> | ||
// testmacros.h | // testmacros.h | ||
Line 50: | Line 55: | ||
#endif | #endif | ||
</syntaxhighlight> | </syntaxhighlight> | ||
}} | |||
</blockquote><!-- PreProcessor Seams --> | </blockquote><!-- PreProcessor Seams --> | ||
Revision as of 14:12, 23 July 2022
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.