{
"$type": "site.standard.document",
"path": "/automated-acceptance-tests/",
"publishedAt": "2016-01-30T13:34:06.000Z",
"site": "at://did:plc:6gssgguzeecdttuw4gpdshg2/site.standard.publication/self",
"tags": [
"spring-boot",
"java",
"selenium"
],
"textContent": "More testing is never a bad thing. Automating that testing is even better. We recently added automated acceptance testing to a spring-boot application.\n\nThere were a few small hiccups to getting it implemented. Which I'd like to share the solutions to.\n\nMultiple Application Contexts\n\nThe 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.\n\nThis can all be fixed if you name the context for your acceptance test class. Just provide a name = value to the @SpringApplicationConfiguration annotation.\n\n[Embedded code (GitHub Gist)]\n\nThis made sure the two contexts were not getting merged.\n\nH2 not Resetting\n\nEven 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.\n\n[Embedded code (GitHub Gist)]\n\nThat's all you need to backup and restore. The overhead is minimal so we can do this before and after each test.\n\nIf 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.\n\nContinuous Integration (Travis-CI)\n\nWe 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.\n\n[Embedded code (GitHub Gist)]\n\nRead the original post with all embeds and interactive content at https://rants.broonix.ca/automated-acceptance-tests/",
"title": "Automated Acceptance Testing with Selenium"
}