Open number133 opened 9 years ago
Hello.
I've been asked for such a feature already (See #39). But I feel it's out of the scope of DbSetup: it would be quite a complex task, and I'm not sure I would end up with an API that would be easier to use than the software's own API. It would also be problematic because the test would have to commit every change before using that new DbSetup API, otherwise the changes would not be visible to DbSetup. In my experience, 99% of DAO tests are tests for methods that query the database and thus return results. The assertions can thus be made on these results. For the remaining 1%, most of the time, a simple query by ID method can be used after the insertion/update/delete to make sure the test did the right thing. So I'm not sure it's worth the effort. Do you have a specific use-case, and some pseudo-code, in mind?
Currently we are using DBSetup to initialize data for integration tests. We don't want use our own API to init data or check results, because we are planning significant refactoring. If we use our API, we can't rely on tests after the refactoring. So now I decide to use http://jdbi.org/ to verify results. DBSetup is quite easy, concise and powerful tool and it would be nice to have same style verification tool.
+1
@number133 how do you verify results using JDBI? Do you have an example? Thanks.
But I feel it's out of the scope of DbSetup
Maybe you can create a new repository for this, like DbExpect.
What do you think about https://github.com/joel-costigliola/assertj-db ?
Use case you setup & assert should be in one project is that you can reuse setup in tests. https://github.com/JDBDT/jdbdt
How about to add API to check database state? It would be nice to both initiate data and verify it after tests, not using software's own API.