There are plenty of resources that explain what unit and integration testing are and why they are important. That is not what I am asking here.
I am trying to understand how unit/integration tests are run and how they work.
I have a very tenuous grasp of how these tests work behind the scenes and I'd like some help in understanding them. I'm not asking about the inner workings of specific testing frameworks but what happens with the code when you decide to run a test.
Based on my understanding:
You have a function
Foo() and in a separate class, you write a test for
TestFoo(). You decide to run your test using some framework. When running the test, the framework spins up a running version of your code and a fake mock database and uses the test inputs given in
TestFoo to call
Foo. Any dependency injected code is mocked away via the test and given dummy values as well. Once the function
Foo() is done executing, we assert that the results are as expected.
You have a test that covers multiple units of the system including hitting a dev database. You run the test which spins up a running platform, calls
Foo() and queries the return values and/or database for the appropriate changes.
As you can tell, it's a very handwavy explanation. I'd like to some help to flesh out my understanding of how the tests are run, how mocks are set up and how the tests manage to call functions with mock/live components.