Mavenがプロジェクトをビルドして単体テストを実行すると、同時の変更例外がスローされることがあります(5回のうち約1回が失敗し、正常にビルドされます)。しかし、テストをローカルでユニットテストとして実行すると、例外なくすべてテストに合格します。私のpom.xmlファイルでMaven 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>
しかし、私は同時変更例外の原因を言及していない取り戻すスタックトレース。
私はすべてのテストがビルドをパスしたことに気付きましたが、何らかの理由でMavenが既に合格したテストの結果を再印刷しますが、現在はテスト例外ConcurrentModificationがあります。
何が原因でテスト結果が再印刷されるのか、または何らかの理由でテストの最初の実行が並列ビルドであるため完了していない間に、同じ時間にテストが再実行されているかどうかわかりません? (それは、テストを再実行する理由わからない)
スタックトレース
は[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
私は同時変更例外を引き起こすか、またはどのようにそれが唯一の時々起こるようにこの問題の発生を避けるためですかわからないのですが、それはあります同じテストは失敗し、私のテストスイートでは他のテストは失敗します。
あなたのテストを並行して実行することができず、いくつかの状態を共有することができない可能性がありますか?あなたはそれらを見せることができますか?完全なスタックトレースも投稿できますか? – Tunaki
テストされているコードが状態を共有していないことを確認しました。 stacktraceは正常に実行されたテストだけでなく、他のテストが実行されたものです。しかし、stacktraceの中でstacktraceに含まれているもの以外に並行変更の例外について言及していないので、どこから来るのか分かりません。 – diepjy
完全なスタックトレースはコンソールにはなくレポートファイルにあります。コンソールに入れたい場合は、 'mvn -Dsurefire.useFile = false test'を実行します。 – Tunaki