cactoos-jdbc
cactoos-jdbc copied to clipboard
Class that prepopulates database for tests
I find it very difficult to test classes from com.github.fabriciofx.cactoos.jdbc.rset, because real data in database is required. In SelectTest.select() there is a code that can be used for that purpose. How about moving it to object that will make possible to reuse it?
@Iprogrammerr Hi Igor! That's a good idea, but won't break this rule?
@fabriciofx the rule "Test Methods Must Share Nothing" is not 100% right, IMHO. You can share data/code among the tests, but you cannot do this in a specific order like "method A should run before B, then C". Another thing is: if you share data among tests, you need to guarantee that the data should came back to its initial state before use it in another test.
@mdbs99 Thanks for sharing your knowledge with us! But when you're saying "method A should run before B, then C" and "if you share data among tests, you need to guarantee that the data should came back to its initial state before use it in another test." there isn't a conflict between them, because I should use setup() and teardown() methods to achieve it?
If there is not conflict (eg. the data is readonly, it's always in the same state), you don't need to use setup() and teardown().
@fabriciofx In this case table/tables with some records is precondition for testing classes from specific package(rset in this case). So this rule does not apply here. Moreover, we can make this class configurable so if will prepopulate databse with table that can be defined dynamically, so that our test will not depend on some specific table.