H2

Integration testing using H2Database

Reading Time: 3 minutes Need of Integration Testing For doing unit tests, We use to do mocking. Consider we call getUser(), it calls the DAO that’s been mocked and returns “John” for the name and “21” for the age, assembles them and everything is perfect. No need to actually unit test a database there.What if there is any bug in database operations. If you mocked the database you can Continue Reading

Writing Independent Tests

Reading Time: 2 minutes What does it mean for a test to be independent? It means that a test should not depend upon the presence or absence of other tests, the order of the tests, or whether or not previous tests failed or not. It also means that the tests should not be dependent upon external things such environment variables, an internet connection, or the local time. Why is Continue Reading

Integration Testing with H2

Reading Time: 3 minutes It goes without saying that testing code is essential, if you don’t want to have buggy code in production, but how can you test code that queries a database? One solution is an in-memory database, and a common in-memory database is H2. Here is some code that queries a database. More specifically the method getNumDistinctInColumn returns the number of distinct values in a specified column Continue Reading