a discussion that rose among us devs: how to do unit test of Business logic layer that depends on data access layer. the two options are
create test data in a test database (for example, H2). let the Business logic layer call the real data access layer that is injected with test database connection.
mock the data access layer.
I can see pros and cons for the two options:
option one imitates production more closely. however, it compromises the isolation of the unit test. the test might fail because of a bug in the data access layer.
The 2nd option is vulnerable to the scenario where the logic inside the data access layer changes (with no changes to the api). in that case, the returned mocked value maybe obsolete.
would love to hear opinions on the matter (perhaps more options?)