Reputation: 141
If a developer would be writing integration test, to actually test full functionality of the actual code, how would one exclude mocks? Would that be in a Makefile and how would one do it?
Upvotes: 0
Views: 62
Reputation: 2165
I use polymorphism and factory pattern: mock and real class has the same interface. Factory parameter changes what concrete class (say mock of database or real database) are instantiated. This parameter resides in config file. How this parameter is changed depends on ones CI/build system. I use dedicated different test suits for mocks (unit tests) and integration, functional tests. This way the process is automated and your test framework gives you results what has been broken. Configs of each suit (unit tests or functional) set above mentioned factory parameter.
Upvotes: 0
Reputation: 70353
Generally speaking, you would be building a debug version (with debug symbols etc., including mocks etc.) for development / testing, and a release version (without debug symbols, excluding mocks, with optimization etc.) for integration / packaging / release.
How your build system tells your code that you are building for integration / release, and how you turn that information into the desired code structure, is up to you and your build system. Testing for #ifdef NDEBUG
is pretty common.
Depending on your overall setup, ideally it would be your development-stage test code that sets up your mocks, and you wouldn't run those tests for integration (as that is a different kind of test altogether).
Upvotes: 1