8 Replies Latest reply on Oct 1, 2008 8:30 PM by kragoth

    Debugging JSFUnit tests

    ptfp

      Hi,

      Right now I'm having troubles with some of my JSFUnit tests that fail for some reason. I run my test via an ant build file and write the results to a log file with the ant task

      <batchtest todir="${jsfunit.reports.dir}" ...>

      Now when a test fails all I get in the logfile is
      <failure message="null" type="org.apache.cactus.internal.client.AssertionFailedErrorWrapper">
      junit.framework.AssertionFailedError: null at MyClass.testStuff(Unknown Source)

      I don't get any information about why the assertion failed, what the values in the assertion were or at which line in the code it happened. Is there a way to display that information?
      Furthermore, all that I try to write to System.out or System.err seems to be lost, as the log file just says
      <system-out></system-out>
      <system-err></system-err>

      I have also tried debugging my tests in Eclipse, but it skips all the breakpoints that i set inside my test methods and then gives me the same output as above.

      Does anybody know how I can debug my tests?
      Thanks

        • 1. Re: Debugging JSFUnit tests
          ssilvert

          You should be getting back the same information with JSFUnit that you get with any JUnit test. JSFUnit/Cactus runs the JUnit test on the server and then sends the report back to your ant process. When I do this with Maven I always get back detailed stack traces with assertion values, line numbers, etc.

          See http://jakarta.apache.org/cactus/how_it_works.html

          So it might just be a problem with your ant/JUnit setup. If some of our JSFUnit/Ant experts don't see this question you might try asking in a Cactus mailing list because this is really a matter of Cactus/Ant integration.

          As for your System.out and System.err messages, those will show up on the server side because that is where the body of the test is executed.

          Stan

          • 2. Re: Debugging JSFUnit tests
            ptfp

             

            "stan.silvert@jboss.com" wrote:

            So it might just be a problem with your ant/JUnit setup. If some of our JSFUnit/Ant experts don't see this question you might try asking in a Cactus mailing list because this is really a matter of Cactus/Ant integration.

            I don't think that the problem is related to Ant as I get the same results when I run a test from eclipse (without Ant).
            My JUnit tests are working fine too(showing assertion values, line numbers etc.), both with and without using Ant build files.

            As for the cactus configuration I closely followed the getting started guide on the JSFUnit website, but I'll check again if I missed something...

            • 3. Re: Debugging JSFUnit tests
              kragoth

              First of all, if you want eclipse to stop at the breakpoints for debugging purposes you need to be using remote debugging on your web server (or use an internal server installation for eclipse).

              This is because the test is not executing in eclipse it is executing in your web server. (It is more complicated then that, but for what you are trying to achieve think of it like that).

              This also means that you should be looking in your web server standard out log file to see your log messages. (They may not be there but it would be a good place to start)

              I would recommend setting up some proper logging instead of relying on stdout. Put in some Log4J or equivalent to help you with your logging.

              Also, try isolate where the test is failing or post some code of your test and the line that it is failing on would help.

              Thanks

              • 4. Re: Debugging JSFUnit tests
                ptfp

                 

                "Kragoth" wrote:
                This also means that you should be looking in your web server standard out log file to see your log messages. (They may not be there but it would be a good place to start)

                I already checked my tomcat log files. They don't contain any information about the JSFUnit tests...


                I would recommend setting up some proper logging instead of relying on stdout. Put in some Log4J or equivalent to help you with your logging.

                I have tried logging with Log4J, but the messages weren't written to the logs either. But that could be because I've made I mistake somewhere as I haven't used Log4J before... I'll check that later.


                Also, try isolate where the test is failing or post some code of your test and the line that it is failing on would help.

                My problem is not that one test is failing. It's that whenever there is a test failing I have a hard time figuring out why because I don't get the values in the assertion that failed, its line number etc.


                I've checked my Ant build file again. I have tried using the jsfunitwar task, but I got the same Error that slabside describes here: http://www.jboss.com/index.html?module=bb&op=viewtopic&t=115623.
                But when I manually add the .jar files to my .war file that shouldn't be a problem, right? I checked and all the required .jars are in my WEB-INF/lib directory.
                What does the jsfunitwar ant task do besides copying the required libraries? Because it seems to spend about a minute searching for the .jar files and then just gives me the error message mentioned above.
                When I leave it out of my build file it seems to make no difference.

                • 5. Re: Debugging JSFUnit tests
                  kragoth

                  The reason why your jsfunitwar is not adding the libraries could be a combination of 2 problems.

                  1. Your class path is wrong in your jsfunitwar ant target.
                  See my ant target:

                  <target name="create.jsfunit.exploded.dir" depends="compile.test"
                   if="gekko.web.run.jsftests">
                   <property name="force.jsfunit.run" value="=${gekko.web.run.jsftests}"/>
                  
                   <path id="jsfunit.classpath">
                   <fileset dir="${lib.dir}/jsf-unit">
                   <include name="**/*.jar"/>
                   </fileset>
                   <fileset dir="${gekko-shared.lib.test.dir}">
                   <include name="junit/*.jar"/>
                   </fileset>
                   <fileset dir="${gekko-shared.lib.prod.dir}">
                   <include name="aspectj/*.jar"/>
                   </fileset>
                   </path>
                  
                   <antcall target="copy.jsfunit.exploded.dir.libs"/>
                  
                   <taskdef
                   name="jsfunitwar"
                   classname="org.jboss.jsfunit.ant.JSFUnitWarTask"
                   classpathref="jsfunit.classpath"/>
                  
                   <jsfunitwar srcfile="${exploded.dir}"
                   destfile="${exploded-jsfunit.dir}">
                   <classes dir="${classes.test}"
                   includes="**/jsfunit/**/*.class">
                   </classes>
                   <TestRunner/>
                   </jsfunitwar>
                  
                   </target>
                  


                  2. As of the latest build that I build the jsfunitwar task actually doesn't look for all the correct .jars (This could be fixed havn't build for a couple of weeks)

                  I actually have an ant task that manually copies accross the jars at the moment due to the fact that the ant jsfunitwar isn't quite right for the new version of jsfunit.

                  Would it be possible to email your .war so I can have a look? Maybe I'll be able to find out if it is just a logging issue or something deeper. I just looked at my output and all my logging goes to my log4j files. There is nothing in my tomcat logs. So maybe if you don't get your log4j working that is why you are not seeing anything.

                  The jsfunitwar task does a number of things. The 2 most important are of course copying the required jars into your war. And secondly modifying your web.xml to have the right filters/mappings for the jsfunit tests to run.

                  Did you try what I recommended about remote debugging your tomcat within eclipse to get the breakpoints to work?

                  If you write any log statements in your tests do you see those? Or is it all loging in tests that you can't see?

                  • 6. Re: Debugging JSFUnit tests
                    ptfp

                     

                    "Kragoth" wrote:
                    The reason why your jsfunitwar is not adding the libraries could be a combination of 2 problems.

                    1. Your class path is wrong in your jsfunitwar ant target.

                    No, the class path is definitely correct.


                    2. As of the latest build that I build the jsfunitwar task actually doesn't look for all the correct .jars (This could be fixed havn't build for a couple of weeks)

                    I also haven't built for a week or two, I'm going to try that...


                    Would it be possible to email your .war so I can have a look? Maybe I'll be able to find out if it is just a logging issue or something deeper.


                    I'm afraid I can't email you the .war with the whole application.
                    But for now, the logging is not the important issue anyway. The biggest problem is that when an assertion fails I only get
                    <failure message="null" type="org.apache.cactus.internal.client.AssertionFailedErrorWrapper">
                    junit.framework.AssertionFailedError: null at MyClass.testStuff(Unknown Source)

                    No "expected value a but was value b", no line number where the assertion failed, nothing.
                    I get this when I run my Ant buildfile, when I run the tests from eclipse and even when I try to run the tests in my browser.
                    Does anybody know how I could fix this?

                    • 7. Re: Debugging JSFUnit tests
                      ptfp

                      I'm still working on the same problem.
                      I downloaded the JSFUnit Beta 3, but I still don't get any more output.

                      I wanted to try the tests from the Getting Started guide (http://wiki.jboss.org/wiki/_Files/GettingStartedGuide/jsfunitTomcat.war) to see if these work, but I get this error: https://jira.jboss.org/jira/browse/JSFUNIT-65
                      I have tried replacing the libraries in the .war file with newer ones, but that didn't help.

                      Is there a way to fix this?
                      Or does anybody have a simple JSFUnit test application that works?

                      • 8. Re: Debugging JSFUnit tests
                        kragoth

                        Are you able to set up a break point in eclipse then remotely connect to your app on tomcat and then run your test in eclipse.

                        This should allow you to step through the code and maybe find out a little more?