NetBeans Forums

 FAQFAQ   SearchSearch   MemberlistMemberlist   RegisterRegister   ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 
  

Debugging JUnit Testcases in NetBeans 6.7

 
Post new topic   Reply to topic    NetBeans Forums -> NetBeans Users
View previous topic :: View next topic  
Author Message
wwessels



Joined: 09 Jul 2009
Posts: 4

PostPosted: Thu Jul 09, 2009 12:07 pm    Post subject: Debugging JUnit Testcases in NetBeans 6.7 Reply with quote

Hi,

In NetBeans 6.5.1, I was able to choose 'Run File' and 'Debug File' when I right click on a fil in the Projects view.

When I do that now, I get an error: 'Class <my class> does not have a main method.

I can choose Test File. This causes the JUnit test to execute. Apparently, this is 'the new way' to execute JUnit tests.
How do I debug JUnit tests?

Regards,
Wouter
(NetBeans 6.7 on Mac OS X, Java5)
Back to top
Petr Blaha
Posted via mailing list.





PostPosted: Thu Jul 09, 2009 1:32 pm    Post subject: Debugging JUnit Testcases in NetBeans 6.7 Reply with quote

wwessels wrote:
Quote:
Hi,



In NetBeans 6.5.1, I was able to choose 'Run File' and 'Debug File' when I right click on a fil in the Projects view.



When I do that now, I get an error: 'Class <my class> does not have a main method.



I can choose Test File. This causes the JUnit test to execute. Apparently, this is 'the new way' to execute JUnit tests.

How do I debug JUnit tests?

Debug -> Debug Test File (Ctrl+Shift-F6)

P

Quote:



Regards,

Wouter

(NetBeans 6.7 on Mac OS X, Java5)



Back to top
wwessels



Joined: 09 Jul 2009
Posts: 4

PostPosted: Thu Jul 09, 2009 1:38 pm    Post subject: Reply with quote

YESSS
Thanks, I did not look there Sad

Regards,
Wouter
Back to top
hernan



Joined: 23 Jul 2009
Posts: 6

PostPosted: Thu Jul 23, 2009 6:45 pm    Post subject: Debbuging Junit Groovy Test cases under a Maven Application Reply with quote

I am creating some test cases using the WebTest too and Maven, and writting my test cases in groovy.

This is the pom.xml :

Code:
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
   xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
   <modelVersion>4.0.0</modelVersion>
   <groupId>com.blah</groupId>
   <artifactId>webtestTestCases</artifactId>
   <name>webtestTestCases</name>
   <version>0.0.1-SNAPSHOT</version>
   <description>Automated Test Cases run by WebTest</description>
   <dependencies>
      <dependency>
         <groupId>junit</groupId>
         <artifactId>junit</artifactId>
         <version>4.6</version>
         <scope>test</scope>
      </dependency>
      <dependency>
         <groupId>mysql</groupId>
         <artifactId>mysql-connector-java</artifactId>
         <version>5.1.6</version>
      </dependency>
      <dependency>
         <groupId>com.canoo.webtest</groupId>
         <artifactId>webtest</artifactId>
         <version>3.1-SNAPSHOT</version>
      </dependency>
   </dependencies>
   <repositories>
      <repository>
         <id>webtest_dependencies_snapshot</id>
         <name>WebTest dependencies</name>
         <url>http://webtest.canoo.com/webtest/m2-repo-snapshots</url>
      </repository>
   </repositories>
   <build>
      <plugins>
         <plugin>
            <groupId>org.codehaus.groovy.maven</groupId>
            <artifactId>gmaven-plugin</artifactId>
            <version>1.0-rc-5</version>
            <executions>
               <execution>
                  <goals>
                     <goal>compile</goal>
                     <goal>testCompile</goal>
                  </goals>
               </execution>
            </executions>
         </plugin>
         <plugin>
            <groupId>org.codehaus.mojo</groupId>
            <artifactId>build-helper-maven-plugin</artifactId>   
            <executions>
               <execution>
                  <id>add-test-source</id>
                  <phase>generate-sources</phase>
                  <goals>
                     <goal>add-test-source</goal>
                  </goals>
                  <configuration>
                     <sources>
                        <source>/src/test/groovy</source>
                     </sources>
                  </configuration>
               </execution>
            </executions>
         </plugin>
      </plugins>
   </build>
</project>


All my test cases are under /src/test/groovy. I am able to run them.

But when I try to debug the test cases Debug -> Debug Test File I get this error:
Code:

/.netbeans/6.7/var/cache/executor-snippets/junit-debug.xml:105: The following error occurred while executing this line:
/.netbeans/6.7/var/cache/executor-snippets/junit-debug.xml:73: org.netbeans.modules.java.source.ant.UserCancel
BUILD FAILED (total time: 1 second)


Code:

    <target name="-debug-test-class" depends="-prepare-execution" unless="methodname">
        <junit-debug-template/>
    </target>


Code:

 <translate-classpath classpath="${classpath}" targetProperty="classpath-translated" />



Does anyone know what I am missing? How can I debbug this Junit test cases?[/code]
Back to top
mkleint
Posted via mailing list.





PostPosted: Fri Jul 24, 2009 8:30 am    Post subject: Debugging JUnit Testcases in NetBeans 6.7 Reply with quote

have you executed the "Debug file" or "Debug test" action?
You might try disabling compile on save for the project and see if it
works them.

I've done some work related to execution of scala+groovy files in 6.8
timeframe so there might actually be a bug somewhere. If you can, please
test with the current dev builds as well and let me know.

Milos

hernan wrote:
Quote:
I am creating some test cases using the WebTest too and Maven, and writting my test cases in groovy.



This is the pom.xml :




Code:
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"

xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">

<modelVersion>4.0.0</modelVersion>

<groupId>com.blah</groupId>

<artifactId>webtestTestCases</artifactId>

<name>webtestTestCases</name>

<version>0.0.1-SNAPSHOT</version>

<description>Automated Test Cases run by WebTest</description>

<dependencies>

<dependency>

<groupId>junit</groupId>

<artifactId>junit</artifactId>

<version>4.6</version>

<scope>test</scope>

</dependency>

<dependency>

<groupId>mysql</groupId>

<artifactId>mysql-connector-java</artifactId>

<version>5.1.6</version>

</dependency>

<dependency>

<groupId>com.canoo.webtest</groupId>

<artifactId>webtest</artifactId>

<version>3.1-SNAPSHOT</version>

</dependency>

</dependencies>

<repositories>

<repository>

<id>webtest_dependencies_snapshot</id>

<name>WebTest dependencies</name>

<url>http://webtest.canoo.com/webtest/m2-repo-snapshots</url>

</repository>

</repositories>

<build>

<plugins>

<plugin>

<groupId>org.codehaus.groovy.maven</groupId>

<artifactId>gmaven-plugin</artifactId>

<version>1.0-rc-5</version>

<executions>

<execution>

<goals>

<goal>compile</goal>

<goal>testCompile</goal>

</goals>

</execution>

</executions>

</plugin>

<plugin>

<groupId>org.codehaus.mojo</groupId>

<artifactId>build-helper-maven-plugin</artifactId>

<executions>

<execution>

<id>add-test-source</id>

<phase>generate-sources</phase>

<goals>

<goal>add-test-source</goal>

</goals>

<configuration>

<sources>

<source>/src/test/groovy</source>

</sources>

</configuration>

</execution>

</executions>

</plugin>

</plugins>

</build>

</project>







All my test cases are under /src/test/groovy. I am able to run them.



But when I try to debug the test cases Debug -> Debug Test File I get this error:


Code:


/.netbeans/6.7/var/cache/executor-snippets/junit-debug.xml:105: The following error occurred while executing this line:

/.netbeans/6.7/var/cache/executor-snippets/junit-debug.xml:73: org.netbeans.modules.java.source.ant.UserCancel

BUILD FAILED (total time: 1 second)








Code:


<target name="-debug-test-class" depends="-prepare-execution" unless="methodname">

<junit-debug-template/>

</target>








Code:


<translate-classpath classpath="${classpath}" targetProperty="classpath-translated" />









Does anyone know what I am missing? How can I debbug this Junit test cases?[/code]




Back to top
hernan



Joined: 23 Jul 2009
Posts: 6

PostPosted: Thu Aug 06, 2009 7:15 pm    Post subject: Reply with quote

Thanks mkleint for your answer. Sorry I coudn't do what you asked me.

I have updated the netbeans ide and know it seems that is working.

Every time I do Debug -> Test File it seem that it sends all the maven commands.
Also when I do Run - Test File-

However now I am getting this issue:

Code:

WARNING: multiple versions of ant detected in path for junit
         jar:file:/usr/local/netbeans-6.7/java2/ant/lib/ant.jar!/org/apache/tools/ant/Project.class
     and jar:file:/home/hernan/.m2/repository/org/apache/ant/ant/1.7.1/ant-1.7.1.jar!/org/apache/tools/ant/Project.class
Testsuite: test.BrowseAllCountriesTest
Tests run: 1, Failures: 0, Errors: 1, Time elapsed: 0 sec

Null Test:         Caused an ERROR
test.BrowseAllCountriesTest
java.lang.ClassNotFoundException: test.BrowseAllCountriesTest
        at java.net.URLClassLoader$1.run(URLClassLoader.java:200)
        at java.security.AccessController.doPrivileged(Native Method)
        at java.net.URLClassLoader.findClass(URLClassLoader.java:188)
        at java.lang.ClassLoader.loadClass(ClassLoader.java:307)
        at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:301)
        at java.lang.ClassLoader.loadClass(ClassLoader.java:252)
        at java.lang.ClassLoader.loadClassInternal(ClassLoader.java:320)
        at java.lang.Class.forName0(Native Method)
        at java.lang.Class.forName(Class.java:169)


Test test.BrowseAllCountriesTest FAILED
test:
BUILD SUCCESSFUL (total time: 5 seconds)



If I do a Run Test Project, everything works. But I cannot run a single test. It is really weird beacuse if I try this in Eclipse (Right Click on a Test and Run as Junit it works) but not in Netbeans. Netbeans has better support for Groovy I don't want to move to Eclipse.

Thanks for your help
Back to top
hernan



Joined: 23 Jul 2009
Posts: 6

PostPosted: Thu Aug 06, 2009 7:18 pm    Post subject: Reply with quote

This is the POM File

Code:

<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
   xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
    <modelVersion>4.0.0</modelVersion>
    <groupId>blah</groupId>
    <artifactId>Automation</artifactId>
    <name>Automation</name>
    <version>0.0.1-SNAPSHOT</version>
    <description>Automated Test Cases run by WebTest</description>
    <dependencies>
        <dependency>
            <groupId>mysql</groupId>
            <artifactId>mysql-connector-java</artifactId>
            <version>5.1.6</version>
        </dependency>
        <dependency>
            <groupId>com.canoo.webtest</groupId>
            <artifactId>webtest</artifactId>
            <version>3.1-SNAPSHOT</version>
        </dependency>
    </dependencies>
    <repositories>
        <repository>
            <id>webtest_dependencies_snapshot</id>
            <name>WebTest dependencies</name>
            <url>http://webtest.canoo.com/webtest/m2-repo-snapshots</url>
        </repository>
    </repositories>
    <build>
        <testSourceDirectory>/src/test/groovy</testSourceDirectory>
        <plugins>
            <plugin>
                <groupId>org.codehaus.groovy.maven</groupId>
                <artifactId>gmaven-plugin</artifactId>
                <version>1.0-rc-5</version>
                <configuration>
                    <debug>true</debug>
                    <verbose>true</verbose>
                    <stacktrace>true</stacktrace>
                    <defaultScriptExtension>.groovy</defaultScriptExtension>
                </configuration>
                <executions>
                    <execution>
                        <goals>
                            <goal>compile</goal>
                            <goal>testCompile</goal>
                        </goals>
                    </execution>
                </executions>
            </plugin>
            <plugin>
                <groupId>org.codehaus.mojo</groupId>
                <artifactId>build-helper-maven-plugin</artifactId>
                <executions>
                    <execution>
                        <id>add-test-source</id>
                        <phase>generate-sources</phase>
                        <goals>
                            <goal>add-test-source</goal>
                        </goals>
                        <configuration>
                            <sources>
                                <source>/src/test/groovy</source>
                            </sources>
                        </configuration>
                    </execution>
                </executions>
            </plugin>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-compiler-plugin</artifactId>
                <version>2.0.2</version>
                <configuration>
                    <source>1.6</source>
                    <target>1.6</target>
                </configuration>
            </plugin>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-surefire-plugin</artifactId>
                <configuration>
                    <includes>
                        <include>**/*Test.groovy</include>
                    </includes>
                </configuration>
            </plugin>
        </plugins>
    </build>
</project>
Back to top
hernan



Joined: 23 Jul 2009
Posts: 6

PostPosted: Thu Aug 06, 2009 7:51 pm    Post subject: Reply with quote

When I run a test case under the default package I get this error:
Code:

Testcase: initializationError0(BlahTest):        Caused an ERROR
No runnable methods
java.lang.Exception: No runnable methods
        at java.lang.reflect.Constructor.newInstance(Constructor.java:513)
        at java.lang.reflect.Constructor.newInstance(Constructor.java:513)


Java Result: 2
debug-test:
BUILD SUCCESSFUL (total time: 6 seconds)


However if I run a test case under the test package I get the Class not found error.

[img]
Screenshot.png[/img]



Screenshot.png
 Description:
 Filesize:  47.06 KB
 Viewed:  6778 Time(s)

Screenshot.png


Back to top
mkleint
Posted via mailing list.





PostPosted: Fri Aug 07, 2009 6:30 am    Post subject: Debugging JUnit Testcases in NetBeans 6.7 Reply with quote

hernan wrote:
Quote:
Thanks mkleint for your answer. Sorry I coudn't do what you asked me.



I have updated the netbeans ide and know it seems that is working.



Every time I do Debug -> Test File it seem that it sends all the maven commands.

Also when I do Run - Test File-



However now I am getting this issue:




Code:


WARNING: multiple versions of ant detected in path for junit

jar:file:/usr/local/netbeans-6.7/java2/ant/lib/ant.jar!/org/apache/tools/ant/Project.class

and jar:file:/home/hernan/.m2/repository/org/apache/ant/ant/1.7.1/ant-1.7.1.jar!/org/apache/tools/ant/Project.class

Testsuite: test.BrowseAllCountriesTest

Tests run: 1, Failures: 0, Errors: 1, Time elapsed: 0 sec



Null Test: Caused an ERROR

test.BrowseAllCountriesTest

java.lang.ClassNotFoundException: test.BrowseAllCountriesTest

at java.net.URLClassLoader$1.run(URLClassLoader.java:200)

at java.security.AccessController.doPrivileged(Native Method)

at java.net.URLClassLoader.findClass(URLClassLoader.java:188)

at java.lang.ClassLoader.loadClass(ClassLoader.java:307)

at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:301)

at java.lang.ClassLoader.loadClass(ClassLoader.java:252)

at java.lang.ClassLoader.loadClassInternal(ClassLoader.java:320)

at java.lang.Class.forName0(Native Method)

at java.lang.Class.forName(Class.java:169)





Test test.BrowseAllCountriesTest FAILED

test:

BUILD SUCCESSFUL (total time: 5 seconds)









If I do a Run Test Project, everything works. But I cannot run a single test. It is really weird beacuse if I try this in Eclipse (Right Click on a Test and Run as Junit it works) but not in Netbeans. Netbeans has better support for Groovy I don't want to move to Eclipse.


AFAIK this is a persisting bug in the quick runner of tests. You can
workaround that by always using the maven build to execute tests. That;s
done from the project properties dialog, Compile panel. Switch the
Compile On Save combobox to "Disable".

Milos
Quote:

Thanks for your help




Back to top
hernan



Joined: 23 Jul 2009
Posts: 6

PostPosted: Mon Aug 10, 2009 3:21 pm    Post subject: Reply with quote

Thanks Milos. Now it's working. But I think I found a Netbeans bug.

This is the default debug action:
Code:

jpda.listen=true
maven.surefire.debug=-Xdebug -Xrunjdwp:transport=dt_socket,server=n,address=${jpda.address}
jpda.stopclass=${packageClassName}
forkMode=once
test=${className}


when you select a groovy file and then you go to Debug -> Debug Test file

Netbeans is not taking the className neither the packageClassName variables:

Code:

Port:49587
NetBeans: Executing 'mvn -Djpda.listen=true -Dmaven.surefire.debug=-Xdebug -Xrunjdwp:transport=dt_socket,server=n,address=49587 -Djpda.stopclass= -Djpda.address=49587 -DforkMode=none -Dtest= -Dnetbeans.execution=true test-compile surefire:test'



Do you know if this is a already known bug? If it is not I can report it.

Thanks for your help man!
Back to top
hernan



Joined: 23 Jul 2009
Posts: 6

PostPosted: Tue Aug 11, 2009 12:59 pm    Post subject: Reply with quote

It seems like it's an already known bug

http://forums.netbeans.org/ntopic15153.html
Back to top
WhiteKing



Joined: 18 Jun 2012
Posts: 1

PostPosted: Mon Jun 18, 2012 3:06 am    Post subject: Reply with quote

i did wt u say but im still getting the error, with the difference that im executting the Unit Test of the project, actually my proyect works fine, just when im trying to execute the Unit Test (With JUnit) doesnt works, and im trying to excecute the same test with the same proyect in eclipse and works fine o.O

Code:
 Caught exception while allowing TestExecutionListener [org.springframework.test.context.support.DependencyInjectionTestExecutionListener@4a7437e4] to prepare test instance [example.AlumnoDAOTest@14017fec]
java.lang.IllegalStateException: Failed to load ApplicationContext
   at org.springframework.test.context.TestContext.getApplicationContext(TestContext.java:308)
   at org.springframework.test.context.support.DependencyInjectionTestExecutionListener.injectDependencies(DependencyInjectionTestExecutionListener.java:109)
   at org.springframework.test.context.support.DependencyInjectionTestExecutionListener.prepareTestInstance(DependencyInjectionTestExecutionListener.java:75)
   at org.springframework.test.context.TestContextManager.prepareTestInstance(TestContextManager.java:321)
   at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.createTest(SpringJUnit4ClassRunner.java:211)
   at org.springframework.test.context.junit4.SpringJUnit4ClassRunner$1.runReflectiveCall(SpringJUnit4ClassRunner.java:287)
   at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:15)
   at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.methodBlock(SpringJUnit4ClassRunner.java:289)
   at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.runChild(SpringJUnit4ClassRunner.java:231)
   at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:47)
   at org.junit.runners.ParentRunner$3.run(ParentRunner.java:231)
   at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:60)
   at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:229)
   at org.junit.runners.ParentRunner.access$000(ParentRunner.java:50)
   at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:222)
   at org.springframework.test.context.junit4.statements.RunBeforeTestClassCallbacks.evaluate(RunBeforeTestClassCallbacks.java:61)
   at org.springframework.test.context.junit4.statements.RunAfterTestClassCallbacks.evaluate(RunAfterTestClassCallbacks.java:70)
   at org.junit.runners.ParentRunner.run(ParentRunner.java:300)
   at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.run(SpringJUnit4ClassRunner.java:174)
   at junit.framework.JUnit4TestAdapter.run(JUnit4TestAdapter.java:39)
   at org.apache.tools.ant.taskdefs.optional.junit.JUnitTestRunner.run(JUnitTestRunner.java:520)
   at org.apache.tools.ant.taskdefs.optional.junit.JUnitTestRunner.launch(JUnitTestRunner.java:1060)
   at org.apache.tools.ant.taskdefs.optional.junit.JUnitTestRunner.main(JUnitTestRunner.java:911)
Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'sessionFactory' defined in class path resource [example/dao/context.xml]: Invocation of init method failed; nested exception is java.lang.NoSuchMethodError: org.objectweb.asm.ClassWriter.<init>(I)V
Back to top
Display posts from previous:   
Post new topic   Reply to topic    NetBeans Forums -> NetBeans Users All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You can attach files in this forum
You can download files in this forum


Powered by phpBB
By use of this website, you agree to the NetBeans Policies and Terms of Use. © 2012, Oracle Corporation and/or its affiliates. Sponsored by Oracle logo