Mocking internal classes with Moq for unit testing

You could make internals visible to Moq by adding InternalsVisibleToAttribute in your project’s assembly.cs, like this: [assembly: InternalsVisibleTo(“DynamicProxyGenAssembly2”)] Why “DynamicProxyGenAssembly2” and not “Moq”? It’s the name of dynamic assembly created to contain dynamically generated proxy types (all of this is handled by yet another library, Castle’s DynamicProxy) which is used by Moq. So you expose … Read more

How to unit test Kotlin suspending functions

I’ve found out that it’s because of a CoroutineDispatcher. I used to mock UI context with EmptyCoroutineContext. Switching to Unconfined has solved the problem Update 02.04.20 The name of the question suggests that there’ll be an exhaustive explanation how to unit test a suspending function. So let me explain a bit more. The main problem … Read more

Mocking vs. Test DB?

I think you’ll probably want to do some integration testing to check logic that is enforced by your database structure, for example constraints, triggers, autoincrement columns, etc. You should, however, for unit testing mock out whatever framework components that your DAL relies upon as you want (in your unit tests) to test only those components … Read more

How do you create tests for “make check” with GNU autotools

To make test run when you issue make check, you need to add them to the TESTS variable Assuming you’ve already built the executable that runs the unit tests, you just add the name of the executable to the TESTS variable like this: TESTS=my-test-executable It should then be automatically run when you make check, and … Read more