How to execute scripts before and after SureFire test phase

The name of the pictureThe name of the pictureThe name of the pictureClash Royale CLAN TAG#URR8PPP


How to execute scripts before and after SureFire test phase



When I invoke mvm test, I want to execute a setup.sql script before Surefire JUnit is invoked and then execute a teardown.sql script after.


mvm test


setup.sql


teardown.sql



I know from questions like this how to execute scripts during the test phase, but I have no idea how to define this specific sequence of events. Thank you!





Sounds not like a unit test more like an integration test which means using something different than JUnit and run via maven-failsafe-plugin ...Apart from that you could use sql-maven-plugin
– khmarbaise
yesterday




1 Answer
1



Not with the surefire plugin but with its sibling the failsafe plugin. They both execute Tests but in different life-cycle phases. The surefire plugin in test and the failsafe plugin in integration-test. See life-cycle phases and the default plugin bindings.



The advantage of the failsafe plugin running in the integration test phase is that there are pre- and post- phases.



Since you mention some sql script it seems you want to prepare a database. At that point you are not really doing unit testing anymore but writing an integration test. So using the failsafe plugin makes the most sense here.





Absolutely agree. The failsafe plugin in combination with separating unit from integration tests via categories looks like the best practice solution. Thank you!
– Answoquest
yesterday






By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Popular posts from this blog

Keycloak server returning user_not_found error when user is already imported with LDAP

PHP parse/syntax errors; and how to solve them?

How to scale/resize CVPixelBufferRef in objective C, iOS