Automated Acceptance Testing with Selenium
More testing is never a bad thing. Automating that testing is even better. We recently added automated acceptance testing to a spring-boot application.
There were a few small hiccups to getting it implemented. Which I'd like to share the solutions to.
Multiple Application Contexts
The first issue we ran into was defining the application context for our testing. We wanted to ensure our Integration and Unit tests were not interfering with our Acceptance tests. At first this was causing all kinds of problems. Spring's test runner was merging the two contexts we defined into one.
This can all be fixed if you name the context for your acceptance test class. Just provide a name = value
to the @SpringApplicationConfiguration
annotation.
This made sure the two contexts were not getting merged.
H2 not Resetting
Even if you add the @Transational
annotation to the tests executed by selenium changes will not be rolled back. They are not being done with in the transaction of the test case. Luckily H2 is simple to backup and restore.
That's all you need to backup and restore. The overhead is minimal so we can do this before and after each test.
If you want to persist date for the whole test class use @BeforeClass
and @AfterClass
. I do not recommend this since your tests might become order dependent.
Continuous Integration (Travis-CI)
We use travis to automate our builds. Travis already has built in support for Firefox. All we had to do is add a few lines to our travis config.