在我的第一个Spring Roo项目中,我在测试自动生成的实体测试(entity 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)