为什么在创建ApplicationContext对象后,所有Spring Roo testRemove()测试都会失败?

时间:2013-05-23 14:02:00

标签: spring junit applicationcontext

在我的第一个 Spring Roo 项目中,我注意到在测试自动生成的实体测试时出现了一种奇怪的行为(实体jpa --class~ .xyz --testAutomatically):

在每个生成的 xyzIntegrationTest_Roo_IntegrationTest.aj 文件中, testRemove()测试,例如

@Test
public void xyzImplIntegrationTest.testRemove() {
    xyzImpl obj = dod.getRandomxyzImpl();
    Assert.assertNotNull("Data on demand for 'xyzImpl' failed to initialize correctly", obj);
    Long id = obj.getId();
    Assert.assertNotNull("Data on demand for 'xyzImpl' failed to provide an identifier", id);
    obj = xyzImpl.findxyzImpl(id);
    obj.remove();
    obj.flush();
    // this is the assertion that does not hold
    Assert.assertNull("Failed to remove 'xyzImpl' with identifier '" + id + "'", xyzImpl.findxyzImpl(id));
}

,在JUnit测试队列之后失败我添加以下人工测试并在其他人之前测试它。

import org.junit.Test;
import org.junit.runner.RunWith;
import org.junit.runners.JUnit4;
import org.junit.Assert;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;
import org.springframework.context.support.FileSystemXmlApplicationContext;

@RunWith(JUnit4.class)
public class DummyTest {

  @Test
  public void ArtificialTest() 
  {
    ApplicationContext ac = 
      new ClassPathXmlApplicationContext("classpath*:META-INF/spring/applicationContext.xml");
      // the same problem occurs for
      // new FileSystemXmlApplicationContext("src/main/resources/META-INF/spring/applicationContext.xml");

    Assert.assertTrue(true);
  }
}

请注意,如果独立执行,所有测试都会运行且没有错误,并且我根本没有修改Spring Roo提供的applicationContext.xml。


我现在的问题是:

  • 这是现有解决方法的已知错误还是我遗漏了重要内容?

  • 是否有另一种方法可以获得个人书面测试的应用程序上下文?


在下面找到相应的故障跟踪:

java.lang.AssertionError: Failed to remove 'xyzImpl' with identifier '1' 
at org.junit.Assert.fail(Assert.java:93) 
at org.junit.Assert.assertTrue(Assert.java:43) 
at org.junit.Assert.assertNull(Assert.java:551) 
at xyzImplIntegrationTest_Roo_IntegrationTest.ajc$interMethod$xyzImplIntegrationTest_Roo_IntegrationTest$xyzImplIntegrationTest$testRemove(xyzImplIntegrationTest_Roo_IntegrationTest.aj:118) 
at xyzImplIntegrationTest.testRemove(xyzImplIntegrationTest.java:1) 
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) 
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57) 
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) 
at java.lang.reflect.Method.invoke(Method.java:601) 
at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:45) 
at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:15) 
at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:42) 
at org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:20) 
at org.springframework.test.context.junit4.statements.RunBeforeTestMethodCallbacks.evaluate(RunBeforeTestMethodCallbacks.java:74) 
at org.springframework.test.context.junit4.statements.RunAfterTestMethodCallbacks.evaluate(RunAfterTestMethodCallbacks.java:83) 
at org.springframework.test.context.junit4.statements.SpringRepeat.evaluate(SpringRepeat.java:72) 
at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.runChild(SpringJUnit4ClassRunner.java:231) 
at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:47) 
at org.junit.runners.ParentRunner$3.run(ParentRunner.java:231) 
at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:60) 
at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:229) 
at org.junit.runners.ParentRunner.access$000(ParentRunner.java:50) 
at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:222) 
at org.springframework.test.context.junit4.statements.RunBeforeTestClassCallbacks.evaluate(RunBeforeTestClassCallbacks.java:61) 
at org.springframework.test.context.junit4.statements.RunAfterTestClassCallbacks.evaluate(RunAfterTestClassCallbacks.java:71) 
at org.junit.runners.ParentRunner.run(ParentRunner.java:300) 
at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.run(SpringJUnit4ClassRunner.java:174) 
at org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:50) 
at org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38) 
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:467) 
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:683) 
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:390) 
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:197)

0 个答案:

没有答案