Skip to content

Latest commit

 

History

History
31 lines (20 loc) · 1.65 KB

README.md

File metadata and controls

31 lines (20 loc) · 1.65 KB

dpc-testing

Table of Contents

AbstractDAOTest

This class is used to write tests for DAO objects. It provides a DAOTestExtension configured to use Postgres in a TestContainer for your tests. It takes care of the lifecycle of the container, manages DB migrations and ensures that you have a fresh DB for each of your tests.

For an example of how to use the class, see IpAddressDAOUnitTest.java

For info on TestContainers, see: https://testcontainers.com

For info on DAOTestExtensions, see: Drop Wizard Testing

NoExitSecurityManager

This class is used if you need to write tests for code that calls System.exit(). Normally, if the code you're calling calls System.exit() everything shuts down and your tests stop running. If you replace the security manager with this class, a SystemExitException will be thrown instead that your tests can catch.

Use it like this:

SecurityManager originalSecurityManager = System.getSecurityManager();
System.setSecurityManager(new NoExitSecurityManager());

//<CODE THAT CALLS System.exit() HERE>

System.setSecurityManager(originalSecurityManager);

For an example, see: KeyDeleteUnitTest.java