Fix and improve unit and integration tests.