问题
So i have a small integration test that houses 5 tests in total. Running that test exclusively results in all tests passed. However running my entire test suite results in 4 test failures of the 5.
I've just recently upgraded to grails-2.0 from 1.3.7 and i switched from hsqldb to h2.
Has anyone any pointers in which direction i should be looking in order to fix this (test-pollution) problem?
Domain model
Integration test:
class SeriesIntegrationTests extends GrailsUnitTestCase {
Series series
Episode episode
protected void setUp() {
super.setUp()
series = new Series(ttdbId: 2348);
episode = new Episode(ttdbId: 2983, season: 0, episodeNumber: 0, series: series);
}
protected void tearDown() {
super.tearDown()
}
void testCreateSeries() {
series.save()
assertFalse("should not have validation errors : $series.errors", series.hasErrors())
assertEquals("should be one series stored in db", 1, Series.count())
}
void testCreateEpisode() {
series.save()
episode.save()
assertFalse("should not have validation errors : $episode.errors", episode.hasErrors())
assertEquals("should be one episode stored in db", 1, Episode.count())
}
void testCreateSeriesAndAddEpisode() {
series.addToEpisodes(episode)
series.save(flush: true)
series.refresh()
assertEquals("series should contain one episode", 1, series.episodes.size())
}
void testDeleteSeriesAndCascadeToEpisode() {
series.addToEpisodes(episode)
series.save(flush: true)
series.delete(flush: true)
assertEquals(0, Episode.count())
assertEquals(0, Series.count())
}
void testDeleteSeriesAndCascadeToBackdropImage() {
series.backdrop = new Image();
series.backdrop.binaryData = new byte[0]
series.save(flush: true)
assertFalse(series.hasErrors())
assertEquals(1, Image.count())
series.delete(flush: true)
assertEquals(0, Image.count())
}
}
回答1:
I had a similar problem when moving from 1.3.7 to 2.0. The integration tests were ok when launched with
grails test-app --integration
but were failing when launched with
grails test-app
I fixed everything by converting unit tests to grails 2.0 test (using annotations).
回答2:
My solution as to upgrade all the unit tests to grails 2.0 method of doing tests. When this was done, every test passed. So it seem's that unit tests somehow polluted integration tests. But only on certain hardware configurations.
来源:https://stackoverflow.com/questions/8985152/grails-2-0-integration-test-pollution