Learn how easy it is to sync an existing GitHub or Google Code repo to a SourceForge project! See Demo

Close

new to tool

shreya
2008-01-10
2013-04-25
  • shreya
    shreya
    2008-01-10

    hi can some1 help me in giving a small example of how to configure xml test file and call it in java using sqlunit api??
    its urgent plsss

     
    • David Fishburn
      David Fishburn
      2008-01-11

      For creating the XML test file look at the Oracle sample:

      test\oracle\README

      I have never tried to call it from a Java program, I have always shelled out or run it standalone so can't help you there.

      HTH,
      Dave

       
    • shreya
      shreya
      2008-01-14

      i have configured the xml test file. but how to run it? for that have to call that file using sqlunit api only right?? thats what am asking..

       
    • benjamin
      benjamin
      2008-01-17

      Maybe I'm getting you wrong here, but generally you can call it via ant.

      For use with an Oracle DB, lets assume you have your testfile mytest.xml as follows, residing in the sqlunit-5.0 directory:

      ----------------------------------------mytest.xml----------------------
      <?xml version="1.0"?>
      <!DOCTYPE sqlunit SYSTEM "file:docs/sqlunit.dtd">
      <sqlunit>
      <connection transaction-support="on">
      <driver>oracle.jdbc.driver.OracleDriver</driver>
      <url>jdbc:oracle:thin:@*****:1521:*****</url>
      <user>*****</user>
      <password>******</password>
      </connection>

      <test name="Test0">
      <call>
      <stmt> select 1 from dual</stmt>
      </call>
      <result>
      <resultset id="1">
      <row id="1">
      <col id="1" type="NUMERIC">1</col>
      </row>
      </resultset>
      </result>
      </test>

      </sqlunit>
      --------------------------------------------------------------

      You can call this Testfile by simply typing "ant sqlunit-flat -Dtestfile=mytest.xml" in a command shell.

      Hope this helps,
      Benjamin

       
    • shreya
      shreya
      2008-01-18

      thanxs for the rply. i got it. but now i get connection error.

      "Cannot build Connection (connection-id=null) because oracle.jdbc.driver.OracleDriver not found in specified Context"

      what is to be done for this??

       
      • David Fishburn
        David Fishburn
        2008-01-18

        > "Cannot build Connection (connection-id=null) because oracle.jdbc.driver.OracleDriver not found in specified Context"

        You have set the CLASSPATH right?

        Incidently, I run the sqlunit stuff using this batch file (run.cmd).
        I created it in the root of sqlunit.
        ******
        @echo on

        @if %1. EQU s. goto SINGLE_TEST
        @if %1. EQU d. goto DEBUG_TEST
        @if %1. EQU a. goto ALL_TESTS
        @if %1. EQU t. goto TYPE_TEST

        :ALL_TESTS
        if %2. NE . ant sqlunit-flat -Dtestfile=test/sqlanywhere10/test.xml -Ddebug=true -logfile
        out.txt
        if %2. EQU . ant sqlunit-flat -Dtestfile=test/sqlanywhere10/test.xml -Ddebug=false
        goto END

        :DEBUG_TEST
        ant sqlunit-flat -Dtestfile=test/sqlanywhere10/debug.xml -Ddebug=true
        goto END

        :SINGLE_TEST
        if %2. NE . ant sqlunit-flat -Dtestfile=test/sqlanywhere10/single.xml -Ddebug=true  -logfi
        le out.txt
        if %2. EQU . ant sqlunit-flat -Dtestfile=test/sqlanywhere10/single.xml  -Ddebug=false
        goto END

        :TYPE_TEST
        if %2. NE . ant sqlunit-flat -Dtestfile=test/sqlanywhere10/testtypes.xml -Ddebug=true  -lo
        gfile out.txt
        if %2. EQU . ant sqlunit-flat -Dtestfile=test/sqlanywhere10/testtypes.xml -Ddebug=false
        goto END

        :END
        ******

        Then run it with:
        c:\programs\sqlunit-cvs>run.cmd d

        And just before I run the run.cmd, I set the environment (for my command prompt) using this cmd file (setenv.cmd):
        ******
        1001  9:23:42 c:\programs\sqlunit-cvs>type setenv.cmd

        SET PATH=%JAVA_HOME%\bin;%PATH%
        SET SQLANY_VERSION=10

        if %1. == 9.  SET SQLANY_VERSION=9
        if %SQLANY_VERSION%. == 9.  goto VER9
        goto VER10

        :VER9
        SET CLASSPATH=%ASANY9%\java\jodbc.jar;%ASANYSH9%\jconnect-5_5\classes\jconn2.jar
        goto DIRECTIONS

        :VER10
        SET CLASSPATH=%SQLANY10%\java\jodbc.jar;%SQLANYSH10%\java\jconn2.jar
        goto DIRECTIONS

        :DIRECTIONS
        @echo.
        @echo. To run the TypesTest, you will need to do this:
        @echo. ant junit-test -Dtest.class=net.sourceforge.sqlunit.test.TypesTest
        @echo.

        @echo.
        @echo. You would typically instantiate a connection directly in the JUnit
        @echo. test, see the VendorNameTest.java for an example. Since you do not
        @echo. want to open and destroy the connection over and over, you may
        @echo. consider doing this using the TestSetup decorator as used in
        @echo. TypesTest.java.
        @echo.
        @echo.

        :END
        ******