Когда Maven строит мой проект и запускает модульные тесты, иногда возникает исключение с одновременной модификацией (примерно 1 из 5 раз он будет терпеть неудачу, а в других случаях он будет успешно создан). Но когда я запускаю тесты локально в качестве модульных тестов, все они проходят без исключения.Исключение Maven Surefire Concurrent Modification
В моем файле 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.
Я не уверен, что приведет к перепечатке результатов теста или по какой-либо причине повторное тестирование теста одновременно, пока первый запуск теста не был завершен, поскольку он является параллельной сборкой ? (Не знаю, почему он будет запускать тест)
StackTrace
[Test executing]
13:48:24.869 [00001-main] DEBUG o.s.t.c.s.DirtiesContextTestExecutionListener - After test method: context [[email protected] testClass = Tests, testInstance = [email protected], testMethod = [email protected], testException = [null], mergedContextConfiguration = [[email protected] 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 [[email protected] testClass = Tests, testInstance = [email protected], testMethod = [email protected], testException = [null], mergedContextConfiguration = [[email protected] 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 [[email protected] testClass = Tests, testInstance = [email protected], testMethod = [email protected], testException = java.util.ConcurrentModificationException, mergedContextConfiguration = [[email protected] 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 [[email protected] testClass = Tests, testInstance = [email protected], testMethod = [email protected], testException = java.util.ConcurrentModificationException, mergedContextConfiguration = [[email protected] 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
Я не уверен, что вызывает одновременное изменение Exception или как избежать этой проблемы возникновения, как это происходит только иногда, но это тот же тест, который терпит неудачу, а не другие тесты в моем наборе тестов.
Возможно, потому, что ваши тесты не могут выполняться параллельно и совместно использовать какое-то состояние? Можете ли вы показать им? Можете ли вы также опубликовать полный стек? – Tunaki
Я проверил, что проверяемый код не разделяет какое-либо состояние. Стектура - это просто тест, который успешно выполняется, за которым следуют другие выполняемые тесты. Но нет, где в stacktrace упоминается исключение одновременной модификации, кроме того, что я включил в stacktrace, поэтому я не знаю, откуда он будет поступать от – diepjy
. Полная stacktrace не находится в консоли, а в файле отчетов. Если вы хотите его в консоли, выполните 'mvn -Dsurefire.useFile = false test'. – Tunaki