2010-12-17 22 views
0

antで実行するとテストが合格するのはなぜですか?しかし、Mavenで実行すると失敗する理由はありますか?antで実行してもテストは成功しますが、Mavenで実行すると失敗しますか?

私はWindowsでテストを実行していますが、確かに確信とウィンドウにいくつかの問題がありますか?私はuseSystemClassLoader = FalseとuseManifestOnlyJar = trueを変更しようとしましたが、動作させることができませんでした。スタックは、mavenでテストを実行しているときに発生しているエラーの下にあります。

私が気づいたことの1つは、スタックに$ Proxy.someMethod呼び出しがあることです。どこから来たのかわかりません。

ありがとうございました。

javax.persistence.PersistenceException: org.hibernate.PersistentObjectException: detached entity passed to persist: cheetah.entities.businessdata.Attribute 
     at org.hibernate.ejb.AbstractEntityManagerImpl.convert(AbstractEntityManagerImpl.java:1214) 
     at org.hibernate.ejb.AbstractEntityManagerImpl.convert(AbstractEntityManagerImpl.java:1147) 
     at org.hibernate.ejb.AbstractEntityManagerImpl.convert(AbstractEntityManagerImpl.java:1153) 
     at org.hibernate.ejb.AbstractEntityManagerImpl.persist(AbstractEntityManagerImpl.java:678) 
     at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) 
     at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39) 
     at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25) 
     at java.lang.reflect.Method.invoke(Method.java:597) 
     at org.springframework.orm.jpa.SharedEntityManagerCreator$SharedEntityManagerInvocationHandler.invoke(SharedEntityManagerCreator.java:240) 
     at $Proxy27.persist(Unknown Source) 
     at cheetah.repositories.businessdata.jpa.JpaAttributeRepository.create(JpaAttributeRepository.java:28) 
     at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) 
     at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39) 
     at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25) 
     at java.lang.reflect.Method.invoke(Method.java:597) 
     at org.springframework.aop.support.AopUtils.invokeJoinpointUsingReflection(AopUtils.java:309) 
     at org.springframework.aop.framework.ReflectiveMethodInvocation.invokeJoinpoint(ReflectiveMethodInvocation.java:183) 
     at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:150) 
     at org.springframework.transaction.interceptor.TransactionInterceptor.invoke(TransactionInterceptor.java:110) 
     at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:172) 
     at org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:202) 
     at $Proxy29.create(Unknown Source) 
     at cheetah.tests.integration.util.BusinessDataLookupData.createAttributeLookupData(BusinessDataLookupData.java:19) 
     at cheetah.tests.integration.util.BusinessDataLookupData.create(BusinessDataLookupData.java:10) 
     at cheetah.tests.integration.util.LookupData.create(LookupData.java:7) 
     at cheetah.tests.integration.util.TestUtil.prepareData(TestUtil.java:23) 
     at cheetah.repositories.businessdata.tests.integration.AttributeRepositoryTest.setUpClass(AttributeRepositoryTest.java:23) 
     at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) 
     at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39) 
     at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25) 
     at java.lang.reflect.Method.invoke(Method.java:597) 
     at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:44) 
     at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:15) 
     at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:41) 
     at org.junit.internal.runners.statements.RunBefores.evaluate(RunBefores.java:27) 
     at org.junit.internal.runners.statements.RunAfters.evaluate(RunAfters.java:31) 
     at org.junit.runners.ParentRunner.run(ParentRunner.java:236) 
     at org.apache.maven.surefire.junit4.JUnit4TestSet.execute(JUnit4TestSet.java:59) 
     at org.apache.maven.surefire.suite.AbstractDirectoryTestSuite.executeTestSet(AbstractDirectoryTestSuite.java:120) 
     at org.apache.maven.surefire.suite.AbstractDirectoryTestSuite.execute(AbstractDirectoryTestSuite.java:103) 
     at org.apache.maven.surefire.Surefire.run(Surefire.java:169) 
     at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) 
     at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39) 
     at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25) 
     at java.lang.reflect.Method.invoke(Method.java:597) 
     at org.apache.maven.surefire.booter.SurefireBooter.runSuitesInProcess(SurefireBooter.java:350) 
     at org.apache.maven.surefire.booter.SurefireBooter.main(SurefireBooter.java:1021) 
Caused by: org.hibernate.PersistentObjectException: detached entity passed to persist: cheetah.entities.businessdata.Attribute 
     at org.hibernate.event.def.DefaultPersistEventListener.onPersist(DefaultPersistEventListener.java:127) 
     at org.hibernate.event.def.DefaultPersistEventListener.onPersist(DefaultPersistEventListener.java:61) 
     at org.hibernate.impl.SessionImpl.firePersist(SessionImpl.java:808) 
     at org.hibernate.impl.SessionImpl.persist(SessionImpl.java:782) 
     at org.hibernate.impl.SessionImpl.persist(SessionImpl.java:786) 
     at org.hibernate.ejb.AbstractEntityManagerImpl.persist(AbstractEntityManagerImpl.java:672) 
     ... 43 more 

答えて

0

fireMode = neverを設定すると、確実な設定で問題が解決されました。私は推測が分からないが、このオプションがなければ、mavenはantがあるpre-testコードを実行していない。

1

例外は、分離されたエンティティの問題を示します。 http://www.google.com.au/search?q=javax.persistence+detached+entityには、分離されたエンティティについての数多くのドキュメントがあります。

これらのドキュメントの1つ - 「分離 - 分離されたエンティティは永続的なアイデンティティを持っていますが、現在のところ永続コンテキスト内で積極的に管理されていません。

これからは、Antやmavenではなく、実際にコードに問題があると思われます。

+0

うーん、私はあなたが正しいかもしれないと思います。私はちょうどそれが蟻で渡されたテストが奇妙であることを見いだしますが、それは実際にはありません。 –

1

ほとんどの場合、antビルドでは、antスクリプトとプロパティファイルを経由して、または使用しているantタスク経由で環境のプロパティを設定しています.Mavenビルドはそれを行いません。

これは、Mavenでは失敗し、Antでは発生しないさまざまなテストランタイム設定を残します。ちょっと推測しましたが、前にそれを見ました;-)

1

'pre test code'が実行されていない場合は、Maven failsafeプラグインをチェックし、ライフサイクルの前後の統合テストのフェーズを調べてください。

また、Mavenは、Antの別のクラスパスを使用している可能性が非常に高いです.JARSを参照するのは、独自のローカルリポジトリです。気をつけるべきこと。

+0

+1お薦めいただきありがとうございます。確かに、Surefireは単体テストではなく、統合テストでしか使われていないことに気づいたことはありませんでした。 –

関連する問題