Is trackUserPerformance
within the data access layer?
If no, then you should consider adding the layer. A common—although not the only one—approach is to separate applications into presentation layer, which handles all the UI logic, business layer, which contains the actual logic of the application, and the data access layer which provides persistence.
If yes, you should consider whether unit tests are the most appropriate here, or other types of tests should be used instead. If you rely on unit tests, then the actual database would be mocked, possibly by tampering with the db
property. If you prefer system tests instead, i.e. tests where the actual database will be changed, then either use nested transactions (i.e. the test itself will start a parent transaction and revert it once the code is executed) or snapshots. It takes milliseconds to restore a snapshot, so it shouldn't affect too negatively the speed of the tests.
If no, then you should consider adding the layer. A common—although not the only one—approach is to separate applications into following layers:
presentation layer, which handles all the UI logic
business layer, which contains the actual logic of the application
data access layer which provides persistence.
If yes, you should consider whether unit tests are the most appropriate here, or other types of tests should be used instead.
If you rely on unit tests, then the actual database would be mocked, possibly by tampering with the
db
property.If you prefer system tests instead, i.e. tests where the actual database will be changed, then either use nested transactions (i.e. the test itself will start a parent transaction and revert it once the code is executed) or snapshots. It takes milliseconds to restore a snapshot, so it shouldn't affect too negatively the speed of the tests.