1

什么可能导致此错误

   org.unitils.core.UnitilsException: Error inserting test data from DbUnit dataset for method public void fi.utu.nettiopsu.selenium.student.function.ExamRegistrationTest.examRegistrationTest()
at org.unitils.dbunit.DbUnitModule.insertDataSet(DbUnitModule.java:156)
at org.unitils.dbunit.DbUnitModule$DbUnitListener.beforeTestSetUp(DbUnitModule.java:557)
at org.unitils.core.Unitils$UnitilsTestListener.beforeTestSetUp(Unitils.java:273)
at org.unitils.UnitilsJUnit4TestClassRunner$TestListenerInvokingMethodRoadie.runBeforesThenTestThenAfters(UnitilsJUnit4TestClassRunner.java:151)
at org.junit.internal.runners.MethodRoadie.runTest(MethodRoadie.java:84)
at org.junit.internal.runners.MethodRoadie.run(MethodRoadie.java:49)
at org.unitils.UnitilsJUnit4TestClassRunner.invokeTestMethod(UnitilsJUnit4TestClassRunner.java:95)
at org.junit.internal.runners.JUnit4ClassRunner.runMethods(JUnit4ClassRunner.java:61)
at org.unitils.UnitilsJUnit4TestClassRunner.access$000(UnitilsJUnit4TestClassRunner.java:44)
at org.unitils.UnitilsJUnit4TestClassRunner$1.run(UnitilsJUnit4TestClassRunner.java:62)
at org.junit.internal.runners.ClassRoadie.runUnprotected(ClassRoadie.java:34)
at org.junit.internal.runners.ClassRoadie.runProtected(ClassRoadie.java:44)
at org.unitils.UnitilsJUnit4TestClassRunner.run(UnitilsJUnit4TestClassRunner.java:68)
at org.apache.maven.surefire.junit4.JUnit4TestSet.execute(JUnit4TestSet.java:53)
at org.apache.maven.surefire.junit4.JUnit4Provider.executeTestSet(JUnit4Provider.java:123)
at org.apache.maven.surefire.junit4.JUnit4Provider.invoke(JUnit4Provider.java:104)
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.util.ReflectionUtils.invokeMethodWithArray(ReflectionUtils.java:164)
at org.apache.maven.surefire.booter.ProviderFactory$ProviderProxy.invoke(ProviderFactory.java:110)
at org.apache.maven.surefire.booter.SurefireStarter.invokeProvider(SurefireStarter.java:175)
at org.apache.maven.surefire.booter.SurefireStarter.runSuitesInProcessWhenForked(SurefireStarter.java:107)
at org.apache.maven.surefire.booter.ForkedBooter.main(ForkedBooter.java:68)
    Caused by: org.unitils.core.UnitilsException: File with name com/company/app/selenium/role/function/RegTest.xml cannot be found.
at org.unitils.core.util.FileResolver.resolveFileName(FileResolver.java:118)
at  org.unitils.dbunit.datasetfactory.impl.DefaultDataSetResolver.resolve(DefaultDataSetResolver.java:88)
at org.unitils.dbunit.DbUnitModule.getDataSet(DbUnitModule.java:368)
at org.unitils.dbunit.DbUnitModule.getDataSet(DbUnitModule.java:320)
at org.unitils.dbunit.DbUnitModule.insertDataSet(DbUnitModule.java:147)

我在与我的测试类相同的包中有“丢失”的 xml 文件。

测试类是

          @DataSet({"RegTest.xml"})
      public class RegTest extends TestBase {

即使我没有在注释上定义文件名,我也会得到同样的错误。

4

1 回答 1

4

将 RegTest.xml 文件重新定位到测试/资源。您还需要在文件中使用 unitils.properties 属性:dbUnit.datasetresolver.prefixWithPackageName=false - 此属性表示 unitils 不要在文件之前使用搜索包名称。在所有这些更改之后,unitils 将开始在文件夹 test/resources 中查找 RegTest.xml。

我希望它会有所帮助。

于 2013-03-26T22:08:06.063 回答