Когда Maven строит мой проект и запускает модульные тесты, иногда возникает исключение одновременной модификации (примерно в 1 из 5 раз он завершится ошибкой, в других случаях он будет успешно построен). Но когда я запускаю тесты локально как модульные, все без исключения проходят успешно.
В моем файле pom.xml у меня есть плагин Surefire, настроенный как:
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.19.1</version>
<configuration>
<forkCount>1C</forkCount>
<reuseForks>true</reuseForks>
</configuration>
<dependencies>
<dependency>
<groupId>org.apache.maven.surefire</groupId>
<artifactId>surefire-junit47</artifactId>
<version>2.19.1</version>
</dependency>
</dependencies>
</plugin>
Однако в stacktrace, который я возвращаю, не упоминается, что вызывает исключение одновременной модификации.
Я заметил, что все тесты проходят сборку, но по какой-то причине Maven перепечатывает результат теста, который уже прошел, но теперь имеет тестовое исключение ConcurrentModification.
Я не уверен, что вызывает повторную печать результата теста или по какой-то причине тест повторяется одновременно с тем, что первый запуск теста не был завершен, поскольку это параллельная сборка? (Не уверен, зачем нужно было повторно запускать тест)
Трассировки стека
[Test executing]
13:48:24.869 [00001-main] DEBUG o.s.t.c.s.DirtiesContextTestExecutionListener - After test method: context [DefaultTestContext@375046d6 testClass = Tests, testInstance = com.application.Tests@179181c, testMethod = failingTest@Tests, testException = [null], mergedContextConfiguration = [WebMergedContextConfiguration@3f7b4a61 testClass = Tests, locations = '{}', classes = '{class com.Application}', contextInitializerClasses = '[]', activeProfiles = '{}', propertySourceLocations = '{}', propertySourceProperties = '{}', resourceBasePath = 'src/main/app', contextLoader = 'org.springframework.test.context.web.WebDelegatingSmartContextLoader', parent = [null]]], class dirties context [false], class mode [null], method dirties context [false].
13:48:24.869 [00001-main] DEBUG o.s.t.c.w.ServletTestExecutionListener - Resetting RequestContextHolder for test context [DefaultTestContext@375046d6 testClass = Tests, testInstance = com.application.Tests@179181c, testMethod = failingTest@Tests, testException = [null], mergedContextConfiguration = [WebMergedContextConfiguration@3f7b4a61 testClass = Test, locations = '{}', classes = '{class com.Application}', contextInitializerClasses = '[]', activeProfiles = '{}', propertySourceLocations = '{}', propertySourceProperties = '{}', resourceBasePath = 'src/main/app', contextLoader = 'org.springframework.test.context.web.WebDelegatingSmartContextLoader', parent = [null]]].
[Some other tests executing]
13:48:28.632 [00001-main] DEBUG o.s.t.c.s.DirtiesContextTestExecutionListener - After test method: context [DefaultTestContext@54fde1bc testClass = Tests, testInstance = com.application.Tests@57ffa818, testMethod = failingTest@Tests, testException = java.util.ConcurrentModificationException, mergedContextConfiguration = [WebMergedContextConfiguration@5247834f testClass = Tests, locations = '{}', classes = '{class com.Application}', contextInitializerClasses = '[]', activeProfiles = '{}', propertySourceLocations = '{}', propertySourceProperties = '{}', resourceBasePath = 'src/main/app', contextLoader = 'org.springframework.test.context.web.WebDelegatingSmartContextLoader', parent = [null]]], class dirties context [false], class mode [null], method dirties context [false].
13:48:28.632 [00001-main] DEBUG o.s.t.c.w.ServletTestExecutionListener - Resetting RequestContextHolder for test context [DefaultTestContext@54fde1bc testClass = Tests, testInstance = com.application.Tests@57ffa818, testMethod = failingTest@Tests, testException = java.util.ConcurrentModificationException, mergedContextConfiguration = [WebMergedContextConfiguration@5247834f testClass = Tests, locations = '{}', classes = '{class com.Application}', contextInitializerClasses = '[]', activeProfiles = '{}', propertySourceLocations = '{}', propertySourceProperties = '{}', resourceBasePath = 'src/main/app', contextLoader = 'org.springframework.test.context.web.WebDelegatingSmartContextLoader', parent = [null]]].
failingTest(com.application.Tests) Time elapsed: 0 sec <<< ERROR!
java.util.ConcurrentModificationException
[Some other tests executing]
Results :
Tests in error:
Tests.failingTest» ConcurrentModification
Я не уверен, что вызывает исключение одновременной модификации или как избежать этой проблемы, поскольку это случается только иногда, но это тот же тест, который терпит неудачу, а не другие тесты в моем наборе тестов.
mvn -Dsurefire.useFile=false test
. - person Tunaki   schedule 21.11.2016