You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@ant.apache.org by tmni <te...@ucia.gov> on 2008/05/20 17:14:41 UTC

Defining ant target to run junit tests using dbunit

I am relatively new to ant and am having trouble setting up a target to run a
series of junit tests.
These tests all run fine when I launch them via eclipse.  But if I try to
run ant directly via command prompt, I get errors.  First, I was getting
error like:
Error 'Unexpected failure during bean definition parsing in resource URL
[file:spring-misc-junit.xml] at:
Bean 'mailSender'; nested exception is java.lang.SecurityException: class
“javax.mail.AuthenticationFailedException”’s signer information does not
match signer information of other classes in the same package.

I thought it might have something to do with authenticating to database, so
tried adding the following
dbunit info.  I got an error that there must be at least 1 step in a dbunit
task. I tried adding a task to do
an insert, but don't know why this would be necessary since the test
themselves set up the test data, accessing a test data xml file.  Even with
that change, I get error that oracle driver cannot be loaded.

The tests use dbunit and the underlying database is Oracle (accessed via
Hibernate in application).
I can't figure out how to define the test target and I cannot find a sample
that does this.  Does
anyone have a sample ant build file that runs junit tests that use
dbunit/hibernate/oracle combination??

<target name="test2" depends="init,compile">
  <taskdef classpathref="project.class.path" name="dbunit"
    classname="org.dbunit.ant.DbUnitTask" />
  <dbunit driver="oracle.jdbc.OracleDriver"
   url="jdbc:oracle:thin:@server:port:dbname"
   userid="me"
   password="password">
</dbunit>

-- 
View this message in context: http://www.nabble.com/Defining-ant-target-to-run-junit-tests-using-dbunit-tp17342896p17342896.html
Sent from the Ant - Users mailing list archive at Nabble.com.


---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@ant.apache.org
For additional commands, e-mail: user-help@ant.apache.org


AW: Defining ant target to run junit tests using dbunit

Posted by "Knuplesch, Juergen" <Ju...@icongmbh.de>.
If I read this http://www.dbunit.org/anttask.html right, than you have to use operation, export or compare.

I use JUNIT but not dbunit. I guess somewhere you have to tell the task, what test you are running.



-- 
Jürgen 

Von: tmni [mailto:teresni@ucia.gov] 
Gesendet: Dienstag, 20. Mai 2008 17:15
An: user@ant.apache.org
Betreff: Defining ant target to run junit tests using dbunit


I am relatively new to ant and am having trouble setting up a target to run a series of junit tests.
These tests all run fine when I launch them via eclipse.  But if I try to run ant directly via command prompt, I get errors.  First, I was getting error like:
Error 'Unexpected failure during bean definition parsing in resource URL [file:spring-misc-junit.xml] at:
Bean 'mailSender'; nested exception is java.lang.SecurityException: class "javax.mail.AuthenticationFailedException"'s signer information does not match signer information of other classes in the same package.

I thought it might have something to do with authenticating to database, so tried adding the following dbunit info.  I got an error that there must be at least 1 step in a dbunit task. I tried adding a task to do an insert, but don't know why this would be necessary since the test themselves set up the test data, accessing a test data xml file.  Even with that change, I get error that oracle driver cannot be loaded.

The tests use dbunit and the underlying database is Oracle (accessed via Hibernate in application).
I can't figure out how to define the test target and I cannot find a sample that does this.  Does anyone have a sample ant build file that runs junit tests that use dbunit/hibernate/oracle combination??

<target name="test2" depends="init,compile">
  <taskdef classpathref="project.class.path" name="dbunit"
    classname="org.dbunit.ant.DbUnitTask" />
  <dbunit driver="oracle.jdbc.OracleDriver"
   url="jdbc:oracle:thin:@server:port:dbname"
   userid="me"
   password="password">
</dbunit>

--
View this message in context: http://www.nabble.com/Defining-ant-target-to-run-junit-tests-using-dbunit-tp17342896p17342896.html
Sent from the Ant - Users mailing list archive at Nabble.com.


---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@ant.apache.org
For additional commands, e-mail: user-help@ant.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@ant.apache.org
For additional commands, e-mail: user-help@ant.apache.org


Re: Defining ant target to run junit tests using dbunit

Posted by Carlos Alonso <ca...@unkasoft.com>.
Well, those errors that you're getting about test classes that cannot be 
found are because the specified <fileset> tag under the <batchtests> is 
not pointing to where the tests are. This path problems are very common 
when running ant tasks because is not trivial to understand the way in 
which ant resolves the given paths. Let me give you two or three tips 
before you give up.

If you use eclipse environment to write your ant tasks, you can place 
the mouse's cursor over a path variable and in a few seconds, a text box 
will appear showing you to where the variable is actually pointing, 
otherwise, if no text box appears is because the variable hasn't been 
declared. With this feature, and executing the ant files from the 
eclipse you can be sure that the variables are pointing to where you've 
previously seen.

Be extremely careful with paths declaration, and keep always in mind 
from which directory the ant file is being executed/invoked and to where 
the project basedir property is pointing.

And finally, this issues are frustrating at first, but when you have 
done it a few times, it becomes much easier.

Regards.
Carlos

tmni escribió:
> I give up....
> I tried following your advice re: classpaths.
> The only way I could get the tests to attempt to run was with
> <classpath refid="project.class.path" /> right under my junit tag.
> I tried setting up classpath with the filesets like you said, but I kept
> getting errors that
> the test classes could not be found.
>
> By the way, I had also removed the oracle/dbunit info from my build.xml
> file.  Just didn't
> seem like I should need it, since I don't really need to run any external
> database setup.
> The database is there, and the tests take care of setting up needed data.
>
> I'm back to getting that ridiculous error about the signer information not
> matching signer
> information of other classes in the same package.
>
> I think I'm going to have to give up on using this, I'm wasting too much
> time trying to 
> get this to work....
>
>
> Carlos Alonso-2 wrote:
>   
>> Well, let's go step by step over the classpath definitions that you can 
>> find in the example I attached a few mails ago.
>> The first classpath definition is required to tell the <sql> task where 
>> to find the implementation of the mysql driver (as far as I know, you 
>> did that successfully because the oracle error disappeared).
>> The second classpath definition is required to define the JUnit task 
>> (<taskdef> ant task), and also seems to be alright.
>> Finally, the third classpath definition is required to tell the JUnit 
>> task, where will find the required classes to execute the tests. This is 
>> the classpath definition that you possibly made wrong. You can find this 
>> classpath definition just below the line that reads <junit 
>> haltonfailure...>.
>> Check whether you have these lines or not. Maybe, if you have these 
>> lines written properly and it's still failing, could be because you 
>> failed listing the all the classes that your tests require to be executed.
>>
>> To include a whole folder or part of it to your classpath, you can use 
>> as much <fileset> tags as you want (to reference a set of libraries that 
>> are in the same folder) or <pathelement> tags to specify single 
>> libraries. I advise you to place all the required jars into one single 
>> folder and reference all of them at once by using the <fileset> tag.
>>
>> <property name="lib" value="path/to/directory/containing/jars" />
>>
>> <fileset dir="${lib}">
>> 	<include name="*.jar"/>
>> </fileset>
>>
>> As you can see in the source code from above, I point the fileset element
>> to the folder where all the required jars are enclosed and then , I
>> include only those files that match the specified pattern (*.jar) to the
>> classpath.
>>
>> Tip: If your .jar files where distributed into several folders hanging
>> from a common root (As you can see below), use the following expression
>> <include name="**/*.jar" /> to tell ant that the required files could be
>> found anywhere contained below that point.
>>
>> lib (root)
>>  |
>>  |-> sub-lib1
>>  |      |
>>  |      |-> file1.jar
>>  |      |
>>  |      |-> file2.jar
>>  |-> sub-lib2
>>         |
>>         |-> file3.jar
>>
>>
>> Regards.
>> Carlos
>>
>> tmni escribió:
>>     
>>> I thought I had included the junit.jar in the classpath, but maybe it's
>>> defined improperly.
>>> I didn't see it in your sample, where do you define that part of the
>>> classpath?  I think I'm 
>>> getting confused about the different places the classpaths are defined,
>>> and
>>> how to list
>>> multiple files/directories...
>>>
>>>
>>> Carlos Alonso-2 wrote:
>>>   
>>>       
>>>> Have you included the java junit.jar library into the classpath provided 
>>>> for the junit task?
>>>> The TestListener class is actually included in that .jar file.
>>>>
>>>> Regards.
>>>> Carlos
>>>>
>>>> tmni escribió:
>>>>     
>>>>         
>>>>> I appreciate both attempts to help.
>>>>> I had already viewed that other web page and tried to follow it.  It
>>>>> doesn't
>>>>> provide quite enough
>>>>> detail for me.
>>>>>
>>>>> I did try using some of the sample code provided.  I was able to
>>>>> eliminate
>>>>> the error about not
>>>>> finding the oracle driver.  But now when I try to include a junit
>>>>> taskdef, I
>>>>> get a classpath error that
>>>>> a class needed by JUnitTask (TestListener) is not found.  As far as I
>>>>> can
>>>>> tell, it is on the classpath, so no
>>>>> idea what this all about.  I tried a couple ways of including it in the
>>>>> classpath within the build.xml file.
>>>>>
>>>>> Sure would be nice if someone had a sample who had also written junit
>>>>> tests
>>>>> using dbunit for a web app
>>>>> using Hibernate and Oracle.  I simply cannot get this to work;very
>>>>> frustrating...
>>>>>
>>>>>
>>>>> Carlos Alonso-2 wrote:
>>>>>   
>>>>>       
>>>>>           
>>>>>> Hi tmni,
>>>>>>
>>>>>> About the authentication exception that you're getting, I cannot guess 
>>>>>> neither cause nor solution, but I think the following source code
>>>>>> could 
>>>>>> be helpful.
>>>>>>
>>>>>> The first point is the problem you're getting with the oracle driver 
>>>>>> load. I think that the point is that you have not defined where Ant
>>>>>> can 
>>>>>> find the class that implements the driver. I've never used Oracle, but
>>>>>> I 
>>>>>> don't think it differs much on mysql. In the following source code you 
>>>>>> can check that the .jar file where the driver is implemented is
>>>>>> directly 
>>>>>> pointed out by the classpath argument, so try adding the .jar file to 
>>>>>> the classpath.
>>>>>>
>>>>>> <sql
>>>>>>             driver = "com.mysql.jdbc.Driver"
>>>>>>             password = "pass"
>>>>>>             url = "jdbc:mysql://127.0.0.1/"
>>>>>>             userid = "pass"
>>>>>>             autocommit = "true"
>>>>>>             classpath = "${lib}/mysql-connector-java-5.0.4-bin.jar"
>>>>>>             >
>>>>>>     .
>>>>>>     .
>>>>>>     .
>>>>>> </sql>
>>>>>>
>>>>>> Regarding now to the second problem to set the tests you want to be 
>>>>>> executed, have a look at the code below, instead of dbunit I use Junit 
>>>>>> as you can see, but I don't think they are very different.
>>>>>>
>>>>>> As for the previous situation, you'll have to define a classpath from 
>>>>>> which your tests will be compiled, and then, include them in a
>>>>>> <fileset> 
>>>>>> resource into the <batchtest> task.
>>>>>> The formatter elements that you can see over specify the output that
>>>>>> the 
>>>>>> junit task will produce.
>>>>>>
>>>>>> <taskdef name="junit"
>>>>>>             
>>>>>> classname="org.apache.tools.ant.taskdefs.optional.junit.JUnitTask"
>>>>>>             classpath="${scripts}/tools/ant-junit.jar"
>>>>>> />
>>>>>>
>>>>>> <junit haltonfailure="no" printsummary="on" fork="yes">
>>>>>>             <classpath >
>>>>>>                  <pathelement location="${build}"/>
>>>>>>                  <fileset dir="${lib}">
>>>>>>                     <include name="*.jar"/>
>>>>>>                  </fileset>
>>>>>>             </classpath>
>>>>>>             <formatter type="brief" usefile="false"/>
>>>>>>             <formatter type="xml" />
>>>>>>              <batchtest todir="${results}" >
>>>>>>                  <fileset dir="${src}"
>>>>>> includes="**/*Tests/Test*.java"/>
>>>>>>             </batchtest>
>>>>>>         </junit>
>>>>>>
>>>>>> I hope it may help you.
>>>>>> Regards.
>>>>>> Carlos
>>>>>>
>>>>>> tmni escribió:
>>>>>>     
>>>>>>         
>>>>>>             
>>>>>>> I am relatively new to ant and am having trouble setting up a target
>>>>>>> to
>>>>>>> run a
>>>>>>> series of junit tests.
>>>>>>> These tests all run fine when I launch them via eclipse.  But if I
>>>>>>> try
>>>>>>> to
>>>>>>> run ant directly via command prompt, I get errors.  First, I was
>>>>>>> getting
>>>>>>> error like:
>>>>>>> Error 'Unexpected failure during bean definition parsing in resource
>>>>>>> URL
>>>>>>> [file:spring-misc-junit.xml] at:
>>>>>>> Bean 'mailSender'; nested exception is java.lang.SecurityException:
>>>>>>> class
>>>>>>> “javax.mail.AuthenticationFailedException”’s signer information does
>>>>>>> not
>>>>>>> match signer information of other classes in the same package.
>>>>>>>
>>>>>>> I thought it might have something to do with authenticating to
>>>>>>> database,
>>>>>>> so
>>>>>>> tried adding the following
>>>>>>> dbunit info.  I got an error that there must be at least 1 step in a
>>>>>>> dbunit
>>>>>>> task. I tried adding a task to do
>>>>>>> an insert, but don't know why this would be necessary since the test
>>>>>>> themselves set up the test data, accessing a test data xml file. 
>>>>>>> Even
>>>>>>> with
>>>>>>> that change, I get error that oracle driver cannot be loaded.
>>>>>>>
>>>>>>> The tests use dbunit and the underlying database is Oracle (accessed
>>>>>>> via
>>>>>>> Hibernate in application).
>>>>>>> I can't figure out how to define the test target and I cannot find a
>>>>>>> sample
>>>>>>> that does this.  Does
>>>>>>> anyone have a sample ant build file that runs junit tests that use
>>>>>>> dbunit/hibernate/oracle combination??
>>>>>>>
>>>>>>> <target name="test2" depends="init,compile">
>>>>>>>   <taskdef classpathref="project.class.path" name="dbunit"
>>>>>>>     classname="org.dbunit.ant.DbUnitTask" />
>>>>>>>   <dbunit driver="oracle.jdbc.OracleDriver"
>>>>>>>    url="jdbc:oracle:thin:@server:port:dbname"
>>>>>>>    userid="me"
>>>>>>>    password="password">
>>>>>>> </dbunit>
>>>>>>>
>>>>>>>   
>>>>>>>       
>>>>>>>           
>>>>>>>               
>>>>>> ---------------------------------------------------------------------
>>>>>> To unsubscribe, e-mail: user-unsubscribe@ant.apache.org
>>>>>> For additional commands, e-mail: user-help@ant.apache.org
>>>>>>
>>>>>>
>>>>>>
>>>>>>     
>>>>>>         
>>>>>>             
>>>>>   
>>>>>       
>>>>>           
>>>> ---------------------------------------------------------------------
>>>> To unsubscribe, e-mail: user-unsubscribe@ant.apache.org
>>>> For additional commands, e-mail: user-help@ant.apache.org
>>>>
>>>>
>>>>
>>>>     
>>>>         
>>>   
>>>       
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: user-unsubscribe@ant.apache.org
>> For additional commands, e-mail: user-help@ant.apache.org
>>
>>
>>
>>     
>
>   


---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@ant.apache.org
For additional commands, e-mail: user-help@ant.apache.org


Re: Defining ant target to run junit tests using dbunit

Posted by tmni <te...@ucia.gov>.
I give up....
I tried following your advice re: classpaths.
The only way I could get the tests to attempt to run was with
<classpath refid="project.class.path" /> right under my junit tag.
I tried setting up classpath with the filesets like you said, but I kept
getting errors that
the test classes could not be found.

By the way, I had also removed the oracle/dbunit info from my build.xml
file.  Just didn't
seem like I should need it, since I don't really need to run any external
database setup.
The database is there, and the tests take care of setting up needed data.

I'm back to getting that ridiculous error about the signer information not
matching signer
information of other classes in the same package.

I think I'm going to have to give up on using this, I'm wasting too much
time trying to 
get this to work....


Carlos Alonso-2 wrote:
> 
> Well, let's go step by step over the classpath definitions that you can 
> find in the example I attached a few mails ago.
> The first classpath definition is required to tell the <sql> task where 
> to find the implementation of the mysql driver (as far as I know, you 
> did that successfully because the oracle error disappeared).
> The second classpath definition is required to define the JUnit task 
> (<taskdef> ant task), and also seems to be alright.
> Finally, the third classpath definition is required to tell the JUnit 
> task, where will find the required classes to execute the tests. This is 
> the classpath definition that you possibly made wrong. You can find this 
> classpath definition just below the line that reads <junit 
> haltonfailure...>.
> Check whether you have these lines or not. Maybe, if you have these 
> lines written properly and it's still failing, could be because you 
> failed listing the all the classes that your tests require to be executed.
> 
> To include a whole folder or part of it to your classpath, you can use 
> as much <fileset> tags as you want (to reference a set of libraries that 
> are in the same folder) or <pathelement> tags to specify single 
> libraries. I advise you to place all the required jars into one single 
> folder and reference all of them at once by using the <fileset> tag.
> 
> <property name="lib" value="path/to/directory/containing/jars" />
> 
> <fileset dir="${lib}">
> 	<include name="*.jar"/>
> </fileset>
> 
> As you can see in the source code from above, I point the fileset element
> to the folder where all the required jars are enclosed and then , I
> include only those files that match the specified pattern (*.jar) to the
> classpath.
> 
> Tip: If your .jar files where distributed into several folders hanging
> from a common root (As you can see below), use the following expression
> <include name="**/*.jar" /> to tell ant that the required files could be
> found anywhere contained below that point.
> 
> lib (root)
>  |
>  |-> sub-lib1
>  |      |
>  |      |-> file1.jar
>  |      |
>  |      |-> file2.jar
>  |-> sub-lib2
>         |
>         |-> file3.jar
> 
> 
> Regards.
> Carlos
> 
> tmni escribió:
>> I thought I had included the junit.jar in the classpath, but maybe it's
>> defined improperly.
>> I didn't see it in your sample, where do you define that part of the
>> classpath?  I think I'm 
>> getting confused about the different places the classpaths are defined,
>> and
>> how to list
>> multiple files/directories...
>>
>>
>> Carlos Alonso-2 wrote:
>>   
>>> Have you included the java junit.jar library into the classpath provided 
>>> for the junit task?
>>> The TestListener class is actually included in that .jar file.
>>>
>>> Regards.
>>> Carlos
>>>
>>> tmni escribió:
>>>     
>>>> I appreciate both attempts to help.
>>>> I had already viewed that other web page and tried to follow it.  It
>>>> doesn't
>>>> provide quite enough
>>>> detail for me.
>>>>
>>>> I did try using some of the sample code provided.  I was able to
>>>> eliminate
>>>> the error about not
>>>> finding the oracle driver.  But now when I try to include a junit
>>>> taskdef, I
>>>> get a classpath error that
>>>> a class needed by JUnitTask (TestListener) is not found.  As far as I
>>>> can
>>>> tell, it is on the classpath, so no
>>>> idea what this all about.  I tried a couple ways of including it in the
>>>> classpath within the build.xml file.
>>>>
>>>> Sure would be nice if someone had a sample who had also written junit
>>>> tests
>>>> using dbunit for a web app
>>>> using Hibernate and Oracle.  I simply cannot get this to work;very
>>>> frustrating...
>>>>
>>>>
>>>> Carlos Alonso-2 wrote:
>>>>   
>>>>       
>>>>> Hi tmni,
>>>>>
>>>>> About the authentication exception that you're getting, I cannot guess 
>>>>> neither cause nor solution, but I think the following source code
>>>>> could 
>>>>> be helpful.
>>>>>
>>>>> The first point is the problem you're getting with the oracle driver 
>>>>> load. I think that the point is that you have not defined where Ant
>>>>> can 
>>>>> find the class that implements the driver. I've never used Oracle, but
>>>>> I 
>>>>> don't think it differs much on mysql. In the following source code you 
>>>>> can check that the .jar file where the driver is implemented is
>>>>> directly 
>>>>> pointed out by the classpath argument, so try adding the .jar file to 
>>>>> the classpath.
>>>>>
>>>>> <sql
>>>>>             driver = "com.mysql.jdbc.Driver"
>>>>>             password = "pass"
>>>>>             url = "jdbc:mysql://127.0.0.1/"
>>>>>             userid = "pass"
>>>>>             autocommit = "true"
>>>>>             classpath = "${lib}/mysql-connector-java-5.0.4-bin.jar"
>>>>>             >
>>>>>     .
>>>>>     .
>>>>>     .
>>>>> </sql>
>>>>>
>>>>> Regarding now to the second problem to set the tests you want to be 
>>>>> executed, have a look at the code below, instead of dbunit I use Junit 
>>>>> as you can see, but I don't think they are very different.
>>>>>
>>>>> As for the previous situation, you'll have to define a classpath from 
>>>>> which your tests will be compiled, and then, include them in a
>>>>> <fileset> 
>>>>> resource into the <batchtest> task.
>>>>> The formatter elements that you can see over specify the output that
>>>>> the 
>>>>> junit task will produce.
>>>>>
>>>>> <taskdef name="junit"
>>>>>             
>>>>> classname="org.apache.tools.ant.taskdefs.optional.junit.JUnitTask"
>>>>>             classpath="${scripts}/tools/ant-junit.jar"
>>>>> />
>>>>>
>>>>> <junit haltonfailure="no" printsummary="on" fork="yes">
>>>>>             <classpath >
>>>>>                  <pathelement location="${build}"/>
>>>>>                  <fileset dir="${lib}">
>>>>>                     <include name="*.jar"/>
>>>>>                  </fileset>
>>>>>             </classpath>
>>>>>             <formatter type="brief" usefile="false"/>
>>>>>             <formatter type="xml" />
>>>>>              <batchtest todir="${results}" >
>>>>>                  <fileset dir="${src}"
>>>>> includes="**/*Tests/Test*.java"/>
>>>>>             </batchtest>
>>>>>         </junit>
>>>>>
>>>>> I hope it may help you.
>>>>> Regards.
>>>>> Carlos
>>>>>
>>>>> tmni escribió:
>>>>>     
>>>>>         
>>>>>> I am relatively new to ant and am having trouble setting up a target
>>>>>> to
>>>>>> run a
>>>>>> series of junit tests.
>>>>>> These tests all run fine when I launch them via eclipse.  But if I
>>>>>> try
>>>>>> to
>>>>>> run ant directly via command prompt, I get errors.  First, I was
>>>>>> getting
>>>>>> error like:
>>>>>> Error 'Unexpected failure during bean definition parsing in resource
>>>>>> URL
>>>>>> [file:spring-misc-junit.xml] at:
>>>>>> Bean 'mailSender'; nested exception is java.lang.SecurityException:
>>>>>> class
>>>>>> “javax.mail.AuthenticationFailedException”’s signer information does
>>>>>> not
>>>>>> match signer information of other classes in the same package.
>>>>>>
>>>>>> I thought it might have something to do with authenticating to
>>>>>> database,
>>>>>> so
>>>>>> tried adding the following
>>>>>> dbunit info.  I got an error that there must be at least 1 step in a
>>>>>> dbunit
>>>>>> task. I tried adding a task to do
>>>>>> an insert, but don't know why this would be necessary since the test
>>>>>> themselves set up the test data, accessing a test data xml file. 
>>>>>> Even
>>>>>> with
>>>>>> that change, I get error that oracle driver cannot be loaded.
>>>>>>
>>>>>> The tests use dbunit and the underlying database is Oracle (accessed
>>>>>> via
>>>>>> Hibernate in application).
>>>>>> I can't figure out how to define the test target and I cannot find a
>>>>>> sample
>>>>>> that does this.  Does
>>>>>> anyone have a sample ant build file that runs junit tests that use
>>>>>> dbunit/hibernate/oracle combination??
>>>>>>
>>>>>> <target name="test2" depends="init,compile">
>>>>>>   <taskdef classpathref="project.class.path" name="dbunit"
>>>>>>     classname="org.dbunit.ant.DbUnitTask" />
>>>>>>   <dbunit driver="oracle.jdbc.OracleDriver"
>>>>>>    url="jdbc:oracle:thin:@server:port:dbname"
>>>>>>    userid="me"
>>>>>>    password="password">
>>>>>> </dbunit>
>>>>>>
>>>>>>   
>>>>>>       
>>>>>>           
>>>>> ---------------------------------------------------------------------
>>>>> To unsubscribe, e-mail: user-unsubscribe@ant.apache.org
>>>>> For additional commands, e-mail: user-help@ant.apache.org
>>>>>
>>>>>
>>>>>
>>>>>     
>>>>>         
>>>>   
>>>>       
>>> ---------------------------------------------------------------------
>>> To unsubscribe, e-mail: user-unsubscribe@ant.apache.org
>>> For additional commands, e-mail: user-help@ant.apache.org
>>>
>>>
>>>
>>>     
>>
>>   
> 
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@ant.apache.org
> For additional commands, e-mail: user-help@ant.apache.org
> 
> 
> 

-- 
View this message in context: http://www.nabble.com/Defining-ant-target-to-run-junit-tests-using-dbunit-tp17342896p17411629.html
Sent from the Ant - Users mailing list archive at Nabble.com.


---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@ant.apache.org
For additional commands, e-mail: user-help@ant.apache.org


Re: Defining ant target to run junit tests using dbunit

Posted by Carlos Alonso <ca...@unkasoft.com>.
Well, let's go step by step over the classpath definitions that you can 
find in the example I attached a few mails ago.
The first classpath definition is required to tell the <sql> task where 
to find the implementation of the mysql driver (as far as I know, you 
did that successfully because the oracle error disappeared).
The second classpath definition is required to define the JUnit task 
(<taskdef> ant task), and also seems to be alright.
Finally, the third classpath definition is required to tell the JUnit 
task, where will find the required classes to execute the tests. This is 
the classpath definition that you possibly made wrong. You can find this 
classpath definition just below the line that reads <junit 
haltonfailure...>.
Check whether you have these lines or not. Maybe, if you have these 
lines written properly and it's still failing, could be because you 
failed listing the all the classes that your tests require to be executed.

To include a whole folder or part of it to your classpath, you can use 
as much <fileset> tags as you want (to reference a set of libraries that 
are in the same folder) or <pathelement> tags to specify single 
libraries. I advise you to place all the required jars into one single 
folder and reference all of them at once by using the <fileset> tag.

<property name="lib" value="path/to/directory/containing/jars" />

<fileset dir="${lib}">
	<include name="*.jar"/>
</fileset>

As you can see in the source code from above, I point the fileset element to the folder where all the required jars are enclosed and then , I include only those files that match the specified pattern (*.jar) to the classpath.

Tip: If your .jar files where distributed into several folders hanging from a common root (As you can see below), use the following expression <include name="**/*.jar" /> to tell ant that the required files could be found anywhere contained below that point.

lib (root)
 |
 |-> sub-lib1
 |      |
 |      |-> file1.jar
 |      |
 |      |-> file2.jar
 |-> sub-lib2
        |
        |-> file3.jar


Regards.
Carlos

tmni escribió:
> I thought I had included the junit.jar in the classpath, but maybe it's
> defined improperly.
> I didn't see it in your sample, where do you define that part of the
> classpath?  I think I'm 
> getting confused about the different places the classpaths are defined, and
> how to list
> multiple files/directories...
>
>
> Carlos Alonso-2 wrote:
>   
>> Have you included the java junit.jar library into the classpath provided 
>> for the junit task?
>> The TestListener class is actually included in that .jar file.
>>
>> Regards.
>> Carlos
>>
>> tmni escribió:
>>     
>>> I appreciate both attempts to help.
>>> I had already viewed that other web page and tried to follow it.  It
>>> doesn't
>>> provide quite enough
>>> detail for me.
>>>
>>> I did try using some of the sample code provided.  I was able to
>>> eliminate
>>> the error about not
>>> finding the oracle driver.  But now when I try to include a junit
>>> taskdef, I
>>> get a classpath error that
>>> a class needed by JUnitTask (TestListener) is not found.  As far as I can
>>> tell, it is on the classpath, so no
>>> idea what this all about.  I tried a couple ways of including it in the
>>> classpath within the build.xml file.
>>>
>>> Sure would be nice if someone had a sample who had also written junit
>>> tests
>>> using dbunit for a web app
>>> using Hibernate and Oracle.  I simply cannot get this to work;very
>>> frustrating...
>>>
>>>
>>> Carlos Alonso-2 wrote:
>>>   
>>>       
>>>> Hi tmni,
>>>>
>>>> About the authentication exception that you're getting, I cannot guess 
>>>> neither cause nor solution, but I think the following source code could 
>>>> be helpful.
>>>>
>>>> The first point is the problem you're getting with the oracle driver 
>>>> load. I think that the point is that you have not defined where Ant can 
>>>> find the class that implements the driver. I've never used Oracle, but I 
>>>> don't think it differs much on mysql. In the following source code you 
>>>> can check that the .jar file where the driver is implemented is directly 
>>>> pointed out by the classpath argument, so try adding the .jar file to 
>>>> the classpath.
>>>>
>>>> <sql
>>>>             driver = "com.mysql.jdbc.Driver"
>>>>             password = "pass"
>>>>             url = "jdbc:mysql://127.0.0.1/"
>>>>             userid = "pass"
>>>>             autocommit = "true"
>>>>             classpath = "${lib}/mysql-connector-java-5.0.4-bin.jar"
>>>>             >
>>>>     .
>>>>     .
>>>>     .
>>>> </sql>
>>>>
>>>> Regarding now to the second problem to set the tests you want to be 
>>>> executed, have a look at the code below, instead of dbunit I use Junit 
>>>> as you can see, but I don't think they are very different.
>>>>
>>>> As for the previous situation, you'll have to define a classpath from 
>>>> which your tests will be compiled, and then, include them in a <fileset> 
>>>> resource into the <batchtest> task.
>>>> The formatter elements that you can see over specify the output that the 
>>>> junit task will produce.
>>>>
>>>> <taskdef name="junit"
>>>>             
>>>> classname="org.apache.tools.ant.taskdefs.optional.junit.JUnitTask"
>>>>             classpath="${scripts}/tools/ant-junit.jar"
>>>> />
>>>>
>>>> <junit haltonfailure="no" printsummary="on" fork="yes">
>>>>             <classpath >
>>>>                  <pathelement location="${build}"/>
>>>>                  <fileset dir="${lib}">
>>>>                     <include name="*.jar"/>
>>>>                  </fileset>
>>>>             </classpath>
>>>>             <formatter type="brief" usefile="false"/>
>>>>             <formatter type="xml" />
>>>>              <batchtest todir="${results}" >
>>>>                  <fileset dir="${src}" includes="**/*Tests/Test*.java"/>
>>>>             </batchtest>
>>>>         </junit>
>>>>
>>>> I hope it may help you.
>>>> Regards.
>>>> Carlos
>>>>
>>>> tmni escribió:
>>>>     
>>>>         
>>>>> I am relatively new to ant and am having trouble setting up a target to
>>>>> run a
>>>>> series of junit tests.
>>>>> These tests all run fine when I launch them via eclipse.  But if I try
>>>>> to
>>>>> run ant directly via command prompt, I get errors.  First, I was
>>>>> getting
>>>>> error like:
>>>>> Error 'Unexpected failure during bean definition parsing in resource
>>>>> URL
>>>>> [file:spring-misc-junit.xml] at:
>>>>> Bean 'mailSender'; nested exception is java.lang.SecurityException:
>>>>> class
>>>>> “javax.mail.AuthenticationFailedException”’s signer information does
>>>>> not
>>>>> match signer information of other classes in the same package.
>>>>>
>>>>> I thought it might have something to do with authenticating to
>>>>> database,
>>>>> so
>>>>> tried adding the following
>>>>> dbunit info.  I got an error that there must be at least 1 step in a
>>>>> dbunit
>>>>> task. I tried adding a task to do
>>>>> an insert, but don't know why this would be necessary since the test
>>>>> themselves set up the test data, accessing a test data xml file.  Even
>>>>> with
>>>>> that change, I get error that oracle driver cannot be loaded.
>>>>>
>>>>> The tests use dbunit and the underlying database is Oracle (accessed
>>>>> via
>>>>> Hibernate in application).
>>>>> I can't figure out how to define the test target and I cannot find a
>>>>> sample
>>>>> that does this.  Does
>>>>> anyone have a sample ant build file that runs junit tests that use
>>>>> dbunit/hibernate/oracle combination??
>>>>>
>>>>> <target name="test2" depends="init,compile">
>>>>>   <taskdef classpathref="project.class.path" name="dbunit"
>>>>>     classname="org.dbunit.ant.DbUnitTask" />
>>>>>   <dbunit driver="oracle.jdbc.OracleDriver"
>>>>>    url="jdbc:oracle:thin:@server:port:dbname"
>>>>>    userid="me"
>>>>>    password="password">
>>>>> </dbunit>
>>>>>
>>>>>   
>>>>>       
>>>>>           
>>>> ---------------------------------------------------------------------
>>>> To unsubscribe, e-mail: user-unsubscribe@ant.apache.org
>>>> For additional commands, e-mail: user-help@ant.apache.org
>>>>
>>>>
>>>>
>>>>     
>>>>         
>>>   
>>>       
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: user-unsubscribe@ant.apache.org
>> For additional commands, e-mail: user-help@ant.apache.org
>>
>>
>>
>>     
>
>   


---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@ant.apache.org
For additional commands, e-mail: user-help@ant.apache.org


Re: Defining ant target to run junit tests using dbunit

Posted by tmni <te...@ucia.gov>.
I thought I had included the junit.jar in the classpath, but maybe it's
defined improperly.
I didn't see it in your sample, where do you define that part of the
classpath?  I think I'm 
getting confused about the different places the classpaths are defined, and
how to list
multiple files/directories...


Carlos Alonso-2 wrote:
> 
> Have you included the java junit.jar library into the classpath provided 
> for the junit task?
> The TestListener class is actually included in that .jar file.
> 
> Regards.
> Carlos
> 
> tmni escribió:
>> I appreciate both attempts to help.
>> I had already viewed that other web page and tried to follow it.  It
>> doesn't
>> provide quite enough
>> detail for me.
>>
>> I did try using some of the sample code provided.  I was able to
>> eliminate
>> the error about not
>> finding the oracle driver.  But now when I try to include a junit
>> taskdef, I
>> get a classpath error that
>> a class needed by JUnitTask (TestListener) is not found.  As far as I can
>> tell, it is on the classpath, so no
>> idea what this all about.  I tried a couple ways of including it in the
>> classpath within the build.xml file.
>>
>> Sure would be nice if someone had a sample who had also written junit
>> tests
>> using dbunit for a web app
>> using Hibernate and Oracle.  I simply cannot get this to work;very
>> frustrating...
>>
>>
>> Carlos Alonso-2 wrote:
>>   
>>> Hi tmni,
>>>
>>> About the authentication exception that you're getting, I cannot guess 
>>> neither cause nor solution, but I think the following source code could 
>>> be helpful.
>>>
>>> The first point is the problem you're getting with the oracle driver 
>>> load. I think that the point is that you have not defined where Ant can 
>>> find the class that implements the driver. I've never used Oracle, but I 
>>> don't think it differs much on mysql. In the following source code you 
>>> can check that the .jar file where the driver is implemented is directly 
>>> pointed out by the classpath argument, so try adding the .jar file to 
>>> the classpath.
>>>
>>> <sql
>>>             driver = "com.mysql.jdbc.Driver"
>>>             password = "pass"
>>>             url = "jdbc:mysql://127.0.0.1/"
>>>             userid = "pass"
>>>             autocommit = "true"
>>>             classpath = "${lib}/mysql-connector-java-5.0.4-bin.jar"
>>>             >
>>>     .
>>>     .
>>>     .
>>> </sql>
>>>
>>> Regarding now to the second problem to set the tests you want to be 
>>> executed, have a look at the code below, instead of dbunit I use Junit 
>>> as you can see, but I don't think they are very different.
>>>
>>> As for the previous situation, you'll have to define a classpath from 
>>> which your tests will be compiled, and then, include them in a <fileset> 
>>> resource into the <batchtest> task.
>>> The formatter elements that you can see over specify the output that the 
>>> junit task will produce.
>>>
>>> <taskdef name="junit"
>>>             
>>> classname="org.apache.tools.ant.taskdefs.optional.junit.JUnitTask"
>>>             classpath="${scripts}/tools/ant-junit.jar"
>>> />
>>>
>>> <junit haltonfailure="no" printsummary="on" fork="yes">
>>>             <classpath >
>>>                  <pathelement location="${build}"/>
>>>                  <fileset dir="${lib}">
>>>                     <include name="*.jar"/>
>>>                  </fileset>
>>>             </classpath>
>>>             <formatter type="brief" usefile="false"/>
>>>             <formatter type="xml" />
>>>              <batchtest todir="${results}" >
>>>                  <fileset dir="${src}" includes="**/*Tests/Test*.java"/>
>>>             </batchtest>
>>>         </junit>
>>>
>>> I hope it may help you.
>>> Regards.
>>> Carlos
>>>
>>> tmni escribió:
>>>     
>>>> I am relatively new to ant and am having trouble setting up a target to
>>>> run a
>>>> series of junit tests.
>>>> These tests all run fine when I launch them via eclipse.  But if I try
>>>> to
>>>> run ant directly via command prompt, I get errors.  First, I was
>>>> getting
>>>> error like:
>>>> Error 'Unexpected failure during bean definition parsing in resource
>>>> URL
>>>> [file:spring-misc-junit.xml] at:
>>>> Bean 'mailSender'; nested exception is java.lang.SecurityException:
>>>> class
>>>> “javax.mail.AuthenticationFailedException”’s signer information does
>>>> not
>>>> match signer information of other classes in the same package.
>>>>
>>>> I thought it might have something to do with authenticating to
>>>> database,
>>>> so
>>>> tried adding the following
>>>> dbunit info.  I got an error that there must be at least 1 step in a
>>>> dbunit
>>>> task. I tried adding a task to do
>>>> an insert, but don't know why this would be necessary since the test
>>>> themselves set up the test data, accessing a test data xml file.  Even
>>>> with
>>>> that change, I get error that oracle driver cannot be loaded.
>>>>
>>>> The tests use dbunit and the underlying database is Oracle (accessed
>>>> via
>>>> Hibernate in application).
>>>> I can't figure out how to define the test target and I cannot find a
>>>> sample
>>>> that does this.  Does
>>>> anyone have a sample ant build file that runs junit tests that use
>>>> dbunit/hibernate/oracle combination??
>>>>
>>>> <target name="test2" depends="init,compile">
>>>>   <taskdef classpathref="project.class.path" name="dbunit"
>>>>     classname="org.dbunit.ant.DbUnitTask" />
>>>>   <dbunit driver="oracle.jdbc.OracleDriver"
>>>>    url="jdbc:oracle:thin:@server:port:dbname"
>>>>    userid="me"
>>>>    password="password">
>>>> </dbunit>
>>>>
>>>>   
>>>>       
>>> ---------------------------------------------------------------------
>>> To unsubscribe, e-mail: user-unsubscribe@ant.apache.org
>>> For additional commands, e-mail: user-help@ant.apache.org
>>>
>>>
>>>
>>>     
>>
>>   
> 
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@ant.apache.org
> For additional commands, e-mail: user-help@ant.apache.org
> 
> 
> 

-- 
View this message in context: http://www.nabble.com/Defining-ant-target-to-run-junit-tests-using-dbunit-tp17342896p17364263.html
Sent from the Ant - Users mailing list archive at Nabble.com.


---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@ant.apache.org
For additional commands, e-mail: user-help@ant.apache.org


Re: Defining ant target to run junit tests using dbunit

Posted by Carlos Alonso <ca...@unkasoft.com>.
Have you included the java junit.jar library into the classpath provided 
for the junit task?
The TestListener class is actually included in that .jar file.

Regards.
Carlos

tmni escribió:
> I appreciate both attempts to help.
> I had already viewed that other web page and tried to follow it.  It doesn't
> provide quite enough
> detail for me.
>
> I did try using some of the sample code provided.  I was able to eliminate
> the error about not
> finding the oracle driver.  But now when I try to include a junit taskdef, I
> get a classpath error that
> a class needed by JUnitTask (TestListener) is not found.  As far as I can
> tell, it is on the classpath, so no
> idea what this all about.  I tried a couple ways of including it in the
> classpath within the build.xml file.
>
> Sure would be nice if someone had a sample who had also written junit tests
> using dbunit for a web app
> using Hibernate and Oracle.  I simply cannot get this to work;very
> frustrating...
>
>
> Carlos Alonso-2 wrote:
>   
>> Hi tmni,
>>
>> About the authentication exception that you're getting, I cannot guess 
>> neither cause nor solution, but I think the following source code could 
>> be helpful.
>>
>> The first point is the problem you're getting with the oracle driver 
>> load. I think that the point is that you have not defined where Ant can 
>> find the class that implements the driver. I've never used Oracle, but I 
>> don't think it differs much on mysql. In the following source code you 
>> can check that the .jar file where the driver is implemented is directly 
>> pointed out by the classpath argument, so try adding the .jar file to 
>> the classpath.
>>
>> <sql
>>             driver = "com.mysql.jdbc.Driver"
>>             password = "pass"
>>             url = "jdbc:mysql://127.0.0.1/"
>>             userid = "pass"
>>             autocommit = "true"
>>             classpath = "${lib}/mysql-connector-java-5.0.4-bin.jar"
>>             >
>>     .
>>     .
>>     .
>> </sql>
>>
>> Regarding now to the second problem to set the tests you want to be 
>> executed, have a look at the code below, instead of dbunit I use Junit 
>> as you can see, but I don't think they are very different.
>>
>> As for the previous situation, you'll have to define a classpath from 
>> which your tests will be compiled, and then, include them in a <fileset> 
>> resource into the <batchtest> task.
>> The formatter elements that you can see over specify the output that the 
>> junit task will produce.
>>
>> <taskdef name="junit"
>>             
>> classname="org.apache.tools.ant.taskdefs.optional.junit.JUnitTask"
>>             classpath="${scripts}/tools/ant-junit.jar"
>> />
>>
>> <junit haltonfailure="no" printsummary="on" fork="yes">
>>             <classpath >
>>                  <pathelement location="${build}"/>
>>                  <fileset dir="${lib}">
>>                     <include name="*.jar"/>
>>                  </fileset>
>>             </classpath>
>>             <formatter type="brief" usefile="false"/>
>>             <formatter type="xml" />
>>              <batchtest todir="${results}" >
>>                  <fileset dir="${src}" includes="**/*Tests/Test*.java"/>
>>             </batchtest>
>>         </junit>
>>
>> I hope it may help you.
>> Regards.
>> Carlos
>>
>> tmni escribió:
>>     
>>> I am relatively new to ant and am having trouble setting up a target to
>>> run a
>>> series of junit tests.
>>> These tests all run fine when I launch them via eclipse.  But if I try to
>>> run ant directly via command prompt, I get errors.  First, I was getting
>>> error like:
>>> Error 'Unexpected failure during bean definition parsing in resource URL
>>> [file:spring-misc-junit.xml] at:
>>> Bean 'mailSender'; nested exception is java.lang.SecurityException: class
>>> “javax.mail.AuthenticationFailedException”’s signer information does not
>>> match signer information of other classes in the same package.
>>>
>>> I thought it might have something to do with authenticating to database,
>>> so
>>> tried adding the following
>>> dbunit info.  I got an error that there must be at least 1 step in a
>>> dbunit
>>> task. I tried adding a task to do
>>> an insert, but don't know why this would be necessary since the test
>>> themselves set up the test data, accessing a test data xml file.  Even
>>> with
>>> that change, I get error that oracle driver cannot be loaded.
>>>
>>> The tests use dbunit and the underlying database is Oracle (accessed via
>>> Hibernate in application).
>>> I can't figure out how to define the test target and I cannot find a
>>> sample
>>> that does this.  Does
>>> anyone have a sample ant build file that runs junit tests that use
>>> dbunit/hibernate/oracle combination??
>>>
>>> <target name="test2" depends="init,compile">
>>>   <taskdef classpathref="project.class.path" name="dbunit"
>>>     classname="org.dbunit.ant.DbUnitTask" />
>>>   <dbunit driver="oracle.jdbc.OracleDriver"
>>>    url="jdbc:oracle:thin:@server:port:dbname"
>>>    userid="me"
>>>    password="password">
>>> </dbunit>
>>>
>>>   
>>>       
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: user-unsubscribe@ant.apache.org
>> For additional commands, e-mail: user-help@ant.apache.org
>>
>>
>>
>>     
>
>   


---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@ant.apache.org
For additional commands, e-mail: user-help@ant.apache.org


Re: Defining ant target to run junit tests using dbunit

Posted by tmni <te...@ucia.gov>.
I appreciate both attempts to help.
I had already viewed that other web page and tried to follow it.  It doesn't
provide quite enough
detail for me.

I did try using some of the sample code provided.  I was able to eliminate
the error about not
finding the oracle driver.  But now when I try to include a junit taskdef, I
get a classpath error that
a class needed by JUnitTask (TestListener) is not found.  As far as I can
tell, it is on the classpath, so no
idea what this all about.  I tried a couple ways of including it in the
classpath within the build.xml file.

Sure would be nice if someone had a sample who had also written junit tests
using dbunit for a web app
using Hibernate and Oracle.  I simply cannot get this to work;very
frustrating...


Carlos Alonso-2 wrote:
> 
> Hi tmni,
> 
> About the authentication exception that you're getting, I cannot guess 
> neither cause nor solution, but I think the following source code could 
> be helpful.
> 
> The first point is the problem you're getting with the oracle driver 
> load. I think that the point is that you have not defined where Ant can 
> find the class that implements the driver. I've never used Oracle, but I 
> don't think it differs much on mysql. In the following source code you 
> can check that the .jar file where the driver is implemented is directly 
> pointed out by the classpath argument, so try adding the .jar file to 
> the classpath.
> 
> <sql
>             driver = "com.mysql.jdbc.Driver"
>             password = "pass"
>             url = "jdbc:mysql://127.0.0.1/"
>             userid = "pass"
>             autocommit = "true"
>             classpath = "${lib}/mysql-connector-java-5.0.4-bin.jar"
>             >
>     .
>     .
>     .
> </sql>
> 
> Regarding now to the second problem to set the tests you want to be 
> executed, have a look at the code below, instead of dbunit I use Junit 
> as you can see, but I don't think they are very different.
> 
> As for the previous situation, you'll have to define a classpath from 
> which your tests will be compiled, and then, include them in a <fileset> 
> resource into the <batchtest> task.
> The formatter elements that you can see over specify the output that the 
> junit task will produce.
> 
> <taskdef name="junit"
>             
> classname="org.apache.tools.ant.taskdefs.optional.junit.JUnitTask"
>             classpath="${scripts}/tools/ant-junit.jar"
> />
> 
> <junit haltonfailure="no" printsummary="on" fork="yes">
>             <classpath >
>                  <pathelement location="${build}"/>
>                  <fileset dir="${lib}">
>                     <include name="*.jar"/>
>                  </fileset>
>             </classpath>
>             <formatter type="brief" usefile="false"/>
>             <formatter type="xml" />
>              <batchtest todir="${results}" >
>                  <fileset dir="${src}" includes="**/*Tests/Test*.java"/>
>             </batchtest>
>         </junit>
> 
> I hope it may help you.
> Regards.
> Carlos
> 
> tmni escribió:
>> I am relatively new to ant and am having trouble setting up a target to
>> run a
>> series of junit tests.
>> These tests all run fine when I launch them via eclipse.  But if I try to
>> run ant directly via command prompt, I get errors.  First, I was getting
>> error like:
>> Error 'Unexpected failure during bean definition parsing in resource URL
>> [file:spring-misc-junit.xml] at:
>> Bean 'mailSender'; nested exception is java.lang.SecurityException: class
>> “javax.mail.AuthenticationFailedException”’s signer information does not
>> match signer information of other classes in the same package.
>>
>> I thought it might have something to do with authenticating to database,
>> so
>> tried adding the following
>> dbunit info.  I got an error that there must be at least 1 step in a
>> dbunit
>> task. I tried adding a task to do
>> an insert, but don't know why this would be necessary since the test
>> themselves set up the test data, accessing a test data xml file.  Even
>> with
>> that change, I get error that oracle driver cannot be loaded.
>>
>> The tests use dbunit and the underlying database is Oracle (accessed via
>> Hibernate in application).
>> I can't figure out how to define the test target and I cannot find a
>> sample
>> that does this.  Does
>> anyone have a sample ant build file that runs junit tests that use
>> dbunit/hibernate/oracle combination??
>>
>> <target name="test2" depends="init,compile">
>>   <taskdef classpathref="project.class.path" name="dbunit"
>>     classname="org.dbunit.ant.DbUnitTask" />
>>   <dbunit driver="oracle.jdbc.OracleDriver"
>>    url="jdbc:oracle:thin:@server:port:dbname"
>>    userid="me"
>>    password="password">
>> </dbunit>
>>
>>   
> 
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@ant.apache.org
> For additional commands, e-mail: user-help@ant.apache.org
> 
> 
> 

-- 
View this message in context: http://www.nabble.com/Defining-ant-target-to-run-junit-tests-using-dbunit-tp17342896p17348563.html
Sent from the Ant - Users mailing list archive at Nabble.com.


---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@ant.apache.org
For additional commands, e-mail: user-help@ant.apache.org


Re: Defining ant target to run junit tests using dbunit

Posted by Carlos Alonso <ca...@unkasoft.com>.
Hi tmni,

About the authentication exception that you're getting, I cannot guess 
neither cause nor solution, but I think the following source code could 
be helpful.

The first point is the problem you're getting with the oracle driver 
load. I think that the point is that you have not defined where Ant can 
find the class that implements the driver. I've never used Oracle, but I 
don't think it differs much on mysql. In the following source code you 
can check that the .jar file where the driver is implemented is directly 
pointed out by the classpath argument, so try adding the .jar file to 
the classpath.

<sql
            driver = "com.mysql.jdbc.Driver"
            password = "pass"
            url = "jdbc:mysql://127.0.0.1/"
            userid = "pass"
            autocommit = "true"
            classpath = "${lib}/mysql-connector-java-5.0.4-bin.jar"
            >
    .
    .
    .
</sql>

Regarding now to the second problem to set the tests you want to be 
executed, have a look at the code below, instead of dbunit I use Junit 
as you can see, but I don't think they are very different.

As for the previous situation, you'll have to define a classpath from 
which your tests will be compiled, and then, include them in a <fileset> 
resource into the <batchtest> task.
The formatter elements that you can see over specify the output that the 
junit task will produce.

<taskdef name="junit"
            
classname="org.apache.tools.ant.taskdefs.optional.junit.JUnitTask"
            classpath="${scripts}/tools/ant-junit.jar"
/>

<junit haltonfailure="no" printsummary="on" fork="yes">
            <classpath >
                 <pathelement location="${build}"/>
                 <fileset dir="${lib}">
                    <include name="*.jar"/>
                 </fileset>
            </classpath>
            <formatter type="brief" usefile="false"/>
            <formatter type="xml" />
             <batchtest todir="${results}" >
                 <fileset dir="${src}" includes="**/*Tests/Test*.java"/>
            </batchtest>
        </junit>

I hope it may help you.
Regards.
Carlos

tmni escribió:
> I am relatively new to ant and am having trouble setting up a target to run a
> series of junit tests.
> These tests all run fine when I launch them via eclipse.  But if I try to
> run ant directly via command prompt, I get errors.  First, I was getting
> error like:
> Error 'Unexpected failure during bean definition parsing in resource URL
> [file:spring-misc-junit.xml] at:
> Bean 'mailSender'; nested exception is java.lang.SecurityException: class
> “javax.mail.AuthenticationFailedException”’s signer information does not
> match signer information of other classes in the same package.
>
> I thought it might have something to do with authenticating to database, so
> tried adding the following
> dbunit info.  I got an error that there must be at least 1 step in a dbunit
> task. I tried adding a task to do
> an insert, but don't know why this would be necessary since the test
> themselves set up the test data, accessing a test data xml file.  Even with
> that change, I get error that oracle driver cannot be loaded.
>
> The tests use dbunit and the underlying database is Oracle (accessed via
> Hibernate in application).
> I can't figure out how to define the test target and I cannot find a sample
> that does this.  Does
> anyone have a sample ant build file that runs junit tests that use
> dbunit/hibernate/oracle combination??
>
> <target name="test2" depends="init,compile">
>   <taskdef classpathref="project.class.path" name="dbunit"
>     classname="org.dbunit.ant.DbUnitTask" />
>   <dbunit driver="oracle.jdbc.OracleDriver"
>    url="jdbc:oracle:thin:@server:port:dbname"
>    userid="me"
>    password="password">
> </dbunit>
>
>   


---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@ant.apache.org
For additional commands, e-mail: user-help@ant.apache.org