From: John H. <joh...@gm...> - 2010-10-18 09:33:01
|
If you are using PropertiesBasedJdbcDatabaseTester, you will certainly need to set those system properties before you instantiate it. I would have thought the normal case for this would be setting the system properties from *outside* your Java code, e.g. via JAVA_OPTS, IDE settings, or Ant build properties. If you're going to hard-code the values, you might as well use JdbcDatabaseTester and call the constructor yourself with the values rather than setting them indirectly via system properties. If you are using Spring, you might already have a DataSource bean configured, no? In that case, can you not use the DataSourceDatabaseTester? Regards John Hurst On Mon, Oct 18, 2010 at 10:08 PM, <pha...@ya...> wrote: > Hello! > > I am using DbUnit 2.4.8 (MySQL database 5.1.51) and I have a problem > with my test class. > > Source code: > > public class TestClass extends DBTestCase { > > ... > > public TestClass() { > > System > .setProperty( PropertiesBasedJdbcDatabaseTester.DBUNIT_DRIVER_CLASS, > "com.mysql.jdbc.Driver" ); > > System > .setProperty( PropertiesBasedJdbcDatabaseTester.DBUNIT_CONNECTION_URL, > "jdbc:mysql://localhost/testdb3" ); > > System.setProperty( PropertiesBasedJdbcDatabaseTester.DBUNIT_USERNAME, > "root" ); > > System.setProperty( PropertiesBasedJdbcDatabaseTester.DBUNIT_PASSWORD, > "mypass" ); > // > System.setProperty( PropertiesBasedJdbcDatabaseTester.DBUNIT_SCHEMA, > "" ); > } > > @BeforeClass > public static void setUpBeforeClass() throws Exception { > final ApplicationContext context = new > ClassPathXmlApplicationContext("appCon.xml"); > service = (TestServiceImpl) > context.getBean("testServiceImpl"); > } > > ... > } > > If I use my test class in the way with the constructor and without the > constructor "public TestClass()" with the System.setPropery's I will > get this error (I use several assertEquals in my test methods): > > org.dbunit.assertion.DbAssertionFailedError: driverClass is null > at org.dbunit.assertion.DefaultFailureHandler > $DefaultFailureFactory.createFailure(DefaultFailureHandler.java:265) > at > org > .dbunit > .assertion > .DefaultFailureHandler.createFailure(DefaultFailureHandler.java:110) > at org.dbunit.assertion.SimpleAssert.fail(SimpleAssert.java:90) > at > org.dbunit.assertion.SimpleAssert.assertTrue(SimpleAssert.java:77) > at > org > .dbunit.assertion.SimpleAssert.assertNotNullNorEmpty(SimpleAssert.java: > 61) > at org.dbunit.JdbcDatabaseTester.<init>(JdbcDatabaseTester.java:103) > at > org > .dbunit > .PropertiesBasedJdbcDatabaseTester > .<init>(PropertiesBasedJdbcDatabaseTester.java:68) > at org.dbunit.DBTestCase.newDatabaseTester(DBTestCase.java:70) > at > org.dbunit.DatabaseTestCase.getDatabaseTester(DatabaseTestCase.java:109) > at org.dbunit.DatabaseTestCase.setUp(DatabaseTestCase.java:151) > at junit.framework.TestCase.runBare(TestCase.java:132) > at junit.framework.TestResult$1.protect(TestResult.java:110) > at junit.framework.TestResult.runProtected(TestResult.java:128) > at junit.framework.TestResult.run(TestResult.java:113) > at junit.framework.TestCase.run(TestCase.java:124) > at junit.framework.TestSuite.runTest(TestSuite.java:243) > at junit.framework.TestSuite.run(TestSuite.java:238) > at > org > .junit.internal.runners.JUnit38ClassRunner.run(JUnit38ClassRunner.java: > 83) > at > org > .eclipse > .jdt > .internal > .junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:46) > 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) > > Adding the constructor "public TestClass()" the "service" variable is > null (it seems the setUpBeforeClass() is not called for initialization > of service) and I get the error in line in which the service should > call a method > > java.lang.NullPointerException > at com.mydomain.programm.service. > TestClass.testAddEntity(TestClass.java:118) > 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 junit.framework.TestCase.runTest(TestCase.java:168) > at junit.framework.TestCase.runBare(TestCase.java:134) > at junit.framework.TestResult$1.protect(TestResult.java:110) > at junit.framework.TestResult.runProtected(TestResult.java:128) > at junit.framework.TestResult.run(TestResult.java:113) > at junit.framework.TestCase.run(TestCase.java:124) > at junit.framework.TestSuite.runTest(TestSuite.java:243) > at junit.framework.TestSuite.run(TestSuite.java:238) > at > org > .junit.internal.runners.JUnit38ClassRunner.run(JUnit38ClassRunner.java: > 83) > at > org > .eclipse > .jdt > .internal > .junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:46) > 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) > > So what can I do to solve this problem? I added the constructor, > because I got warnings which is listed in the FAQ section: > http://www.dbunit.org/faq.html#DefaultDataTypeFactory > But now I have these problems and I do not know what's going wrong. > > Thank you in advance & Best Regards phantomiaser. > > > ------------------------------------------------------------------------------ > Download new Adobe(R) Flash(R) Builder(TM) 4 > The new Adobe(R) Flex(R) 4 and Flash(R) Builder(TM) 4 (formerly > Flex(R) Builder(TM)) enable the development of rich applications that run > across multiple browsers and platforms. Download your free trials today! > http://p.sf.net/sfu/adobe-dev2dev > _______________________________________________ > dbunit-user mailing list > dbu...@li... > https://lists.sourceforge.net/lists/listinfo/dbunit-user > -- Life is interfering with my game |