2016-11-21 14 views
2

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 

私は同時変更例外を引き起こすか、またはどのようにそれが唯一の時々起こるようにこの問題の発生を避けるためですかわからないのですが、それはあります同じテストは失敗し、私のテストスイートでは他のテストは失敗します。

+0

あなたのテストを並行して実行することができず、いくつかの状態を共有することができない可能性がありますか?あなたはそれらを見せることができますか?完全なスタックトレースも投稿できますか? – Tunaki

+0

テストされているコードが状態を共有していないことを確認しました。 stacktraceは正常に実行されたテストだけでなく、他のテストが実行されたものです。しかし、stacktraceの中でstacktraceに含まれているもの以外に並行変更の例外について言及していないので、どこから来るのか分かりません。 – diepjy

+0

完全なスタックトレースはコンソールにはなくレポートファイルにあります。コンソールに入れたい場合は、 'mvn -Dsurefire.useFile = false test'を実行します。 – Tunaki

答えて

0

私は、スレッドを作成して実行していた方法を嘲笑していなかったために問題が発生していることがわかりました。(スレッドはリソースを変更していませんでしたが)私はそれを嘲笑しました。解決される。

0

私は同じ問題を抱えていましたが、Java 8のCollections.sort()の変更に関連していました。More information

関連する問題