Fitnesse and DbFit

DbFit for Data Preparation and Testing in Fitnesse

The test automation using Fitnesse is huge popular for integration testing. It is highly demanded to populate the relational database by test data and during the tests. The Fitnesse often checks the data in application tables also.  

I use the quite handy tool DbFit (DbFit: Test-driven database development) that extends the Fitnesse with simple and readable fixtures to deal with relational databases. It contains a set of commands that you usually use against the databases - Query, Insert, Execute, Execute procedure, Execute DDL. It allows to control the transactions usin Commit or Rollbak. The DbFit rollback the data after the test by default.



I've trouble to connect to Oracle 12 using the latest stable DbFit version 3.2.0, because this version of DbFit does not support the newest Oracle Jdbc Drivers. The DbFit cannot initialize the JDBC driver:


dbfit.OracleTest
java.lang.Error: java.lang.reflect.InvocationTargetException at dbfit.api.DbEnvironmentFactory$EnvironmentDescriptor.createEnvironmentInstance(DbEnvironmentFactory.java:68) at dbfit.api.DbEnvironmentFactory.createEnvironmentInstance(DbEnvironmentFactory.java:102) at dbfit.api.DbEnvironmentFactory.newEnvironmentInstance(DbEnvironmentFactory.java:106) at dbfit.OracleTest.(OracleTest.java:5) at java.base/jdk.internal.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method) at java.base/jdk.internal.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62) at java.base/jdk.internal.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45) at java.base/java.lang.reflect.Constructor.newInstance(Constructor.java:490) at java.base/java.lang.Class.newInstance(Class.java:584) at fit.FixtureClass.newInstance(FixtureClass.java:24) at fit.FixtureLoader.instantiateFixture(FixtureLoader.java:62) at fit.FixtureLoader.instantiateFirstValidFixtureClass(FixtureLoader.java:84) at fit.FixtureLoader.disgraceThenLoad(FixtureLoader.java:44) at fit.Fixture.loadFixture(Fixture.java:142) at fit.Fixture.getLinkedFixtureWithArgs(Fixture.java:134) at fit.Fixture.doTables(Fixture.java:79) at fit.FitServer.process(FitServer.java:81) at fit.FitServer.run(FitServer.java:56) at fit.FitServer.main(FitServer.java:41) Caused by: java.lang.reflect.InvocationTargetException at java.base/jdk.internal.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method) at java.base/jdk.internal.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62) at java.base/jdk.internal.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45) at java.base/java.lang.reflect.Constructor.newInstance(Constructor.java:490) at dbfit.api.DbEnvironmentFactory$EnvironmentDescriptor.createEnvironmentInstance(DbEnvironmentFactory.java:65) ... 18 more Caused by: java.lang.Error: Cannot initialise oracle rowset at dbfit.environment.OracleEnvironment.(OracleEnvironment.java:236) ... 23 more Caused by: java.lang.ClassNotFoundException: oracle.jdbc.driver.OracleResultSetImpl at java.base/jdk.internal.loader.BuiltinClassLoader.loadClass(BuiltinClassLoader.java:581) at java.base/jdk.internal.loader.ClassLoaders$AppClassLoader.loadClass(ClassLoaders.java:178) at java.base/java.lang.ClassLoader.loadClass(ClassLoader.java:521) at java.base/java.lang.Class.forName0(Native Method) at java.base/java.lang.Class.forName(Class.java:315) at dbfit.environment.OracleEnvironment.(OracleEnvironment.java:232)

Solution:

I downloaded the source code of  4.0.0-SNAPSHOT, built it and used the new packaged jars instead of version 3.2.0 libraries. It works. I tested it using Fintesse-20220319. 

Find the attached complete installation of Fitnesse 20220319 with DbFit 4.0.0-SNAPSHOT for Oracle:

https://drive.google.com/file/d/1PcEOGktkLcbE8iaRKF-8PQtU6p9SM__n/view?usp=sharing


Example:

There is the simple example of test that creates table, inserts rows, get query and drop the table:


Contents:



    classpath: lib/*.jar

    dbfit.OracleTest


    Connectjdbc:oracle:thin:username/password@(description=(address_list=(address=(protocol=tcp)(port=1521)(host=localhost)))(connect_data=(SERVICE_NAME=SVC_DBSIM)))


    Execute ddlcreate table TEST_TABLE(ID int, NAME varchar(50))


    InsertTEST_TABLE
    IDNAME
    1Yan
    2John
    3Jan


    Queryselect NAME from TEST_TABLE where ID=2
    NAME
    John


    Execute ddldrop table TEST_TABLE



    Komentáře

    Populární příspěvky z tohoto blogu