cactoos-jdbc icon indicating copy to clipboard operation
cactoos-jdbc copied to clipboard

Class that prepopulates database for tests

Open BinaryIgor opened this issue 6 years ago • 5 comments

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?

BinaryIgor avatar Dec 15 '18 14:12 BinaryIgor

@Iprogrammerr Hi Igor! That's a good idea, but won't break this rule?

fabriciofx avatar Dec 17 '18 17:12 fabriciofx

@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 avatar Dec 17 '18 18:12 mdbs99

@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?

fabriciofx avatar Dec 17 '18 18:12 fabriciofx

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().

mdbs99 avatar Dec 17 '18 18:12 mdbs99

@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.

BinaryIgor avatar Dec 17 '18 21:12 BinaryIgor