I've got a base class that all my controller tests extend. This is set up so each unit test can have its own Fixture to load from.
So the @Before override will check what the required fixture for the test is, load it and then start the test.
The problem here is that this reloads the fixture every single time. Even if the method only did a select on the database, altering nothing.
The internal memory database the Play Framework uses is the H2 database. I wonder if there is a way to check after a unit test is done, if there has been a change to the database and if not, skip the reloading of the exact same data.
I tried identity_scope, it returns null no matter what.
It is meant to make sure that definable modules of code work as expected. To test an application it is not enough to use unit tests. You must also perform functional testing and regression testing. Database access falls outside the scope of unit testing, so you would not write unit tests that include database access.
Database Unit testing requires that the tester should have knowledge in checking tables, writing queries and writing procedures, so to make tests effectively. Testing can be performed in a web application or desktop because the database can be used in the application.
H2 has no possiblity of checking when were last changes applied. However You could just make an additional column that saves last modification time with
CREATE TABLE TEST(ID INT, NAME VARCHAR, LAST_MOD TIMESTAMP AS NOW());
That way You could save a time of test start, and then query the DB if there are any modification dates after the test start time.
I don't see any other possible way
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With