cxf-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From conflue...@apache.org
Subject [CONF] Apache CXF > Testing-Debugging
Date Fri, 14 Aug 2009 13:48:00 GMT
<html>
<head>
    <base href="http://cwiki.apache.org/confluence">
            <link rel="stylesheet" href="/confluence/s/1519/1/11/_/styles/combined.css?spaceKey=CXF&amp;forWysiwyg=true"
type="text/css">
    </head>
<body style="background-color: white" bgcolor="white">
<div id="pageContent">
<div id="notificationFormat">
<div class="wiki-content">
<div class="email">
     <h2><a href="http://cwiki.apache.org/confluence/display/CXF/Testing-Debugging">Testing-Debugging</a></h2>
     <h4>Page <b>edited</b> by             <a href="http://cwiki.apache.org/confluence/display/~dkulp">Daniel
Kulp</a>
    </h4>
     
          <br/>
     <div class="notificationGreySide">
         <p>CXF uses a standard maven build system and unit testing conventions.   For
those not familiar with that, here are some basic hints:</p>

<h4><a name="Testing-Debugging-Unittesting"></a>Unit testing</h4>
<ul>
	<li>We use JUnit as the testing API for writing tests.</li>
	<li>Tests live with the module in the src/test/java directory.  In general, the src/test/java
directory would have the same package layout as the src/main/java.  This allows the tests
to test the package protected methods.</li>
	<li>We use <a href="http://www.easymock.org/" rel="nofollow">Easymock</a>
as our mock framework for producing more complex unit tests.</li>
	<li>To run all the tests in a module, just run "mvn test" in the module.</li>
	<li>To run a single test in a module, run "mvn test -Dtest=MyTest" where MyTest is
the name of the test class (no package specified) that you want to run.</li>
</ul>



<h4><a name="Testing-Debugging-System%2FIntegrationtesting"></a>System/Integration
testing</h4>
<p>We have a special "systest" maven module that contains a large number of more complex
test cases that involve full client/server interactions, server startups, etc...  For the
most part, they are just JUnit tests exactly like above, but test broader aspects.   We have
special utility classes (see below) to help these tests fork server process, test results,
etc...   Running the systests is exactly like running the unit tests, just in the systest
module.</p>


<h4><a name="Testing-Debugging-Usabletestingutilityclasses"></a>Usable testing
utility classes</h4>
<ul>
	<li>org.apache.cxf.test.AbstractCXFTest - in the core module, we have a utility class
that provides a few methods to help write tests.   Things like creating a bus, doing xpath
asserts on XML return values, etc...</li>
	<li>testutils module - top level, we have a testutils module that contains a BUNCH
of utilities:
	<ul>
		<li>in org.apache.cxf.testutils.common, there are utility classes for forking servers,
capturing the output, etc...   The systests use this extensively.</li>
		<li>The rest of testutils consist of a bunch of wsdls with generated code (wsdl2java)
and sample server impls that implement those services.   Other tests can then "share" those
impls.   This is to prevent having "HelloWorld" server impls all over the place.</li>
	</ul>
	</li>
</ul>


<h4><a name="Testing-Debugging-Debugging"></a>Debugging</h4>
<p>There are generally two ways of running a test in a debugger.</p>
<ol>
	<li>Within the IDE.  If you <a href="/confluence/display/CXF/Setting+up+Eclipse"
title="Setting up Eclipse">setup eclipse</a> properly, almost all the tests are runnable
directly in eclipse.   Right click on the test and select "Run As -&gt; JUnit Test" (or
"Debug As").   The test should just run.</li>
	<li>Externally via jpda.   This is much harder.  By default, mvn will fork the unit
tests into a JVM that doesn't have JPDA enabled.   However, it can be done.   First, set your
MAVEN_OPTS like:
<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<pre class="code-java">
export JPDA_OPTS=<span class="code-quote">"-Xdebug -Xrunjdwp:transport=dt_socket,address=8000,server=y,suspend=n"</span>
export MAVEN_OPTS=<span class="code-quote">"-XX:MaxPermSize=192m -Xmx512M $JPDA_OPTS"</span>
</pre>
</div></div>
<p>Then you would need to run the test like "mvn test -Dtest=MyTest -Dsurefire.fork.mode=never".
 When mvn starts, you can attach your external debugger to it and assign breakpoints and such.</p></li>
</ol>


<p><b>Caveats:</b> When debugging systests, they tend to fork background
servers.   If you need to debug the server side part of the interaction, you will need to
disable that forking.   Usually, the easiest way is to find the "setup" code for the test
and look for a "launchServer(Server.class)" line and add a ", true" parameter to tell the
server launcher to run the server "in process".</p>

     </div>
     <div id="commentsSection" class="wiki-content pageSection">
       <div style="float: right;">
            <a href="http://cwiki.apache.org/confluence/users/viewnotifications.action"
class="grey">Change Notification Preferences</a>
       </div>

       <a href="http://cwiki.apache.org/confluence/display/CXF/Testing-Debugging">View
Online</a>
       |
       <a href="http://cwiki.apache.org/confluence/pages/diffpagesbyversion.action?pageId=66629&revisedVersion=5&originalVersion=4">View
Change</a>
              |
       <a href="http://cwiki.apache.org/confluence/display/CXF/Testing-Debugging?showComments=true&amp;showCommentArea=true#addcomment">Add
Comment</a>
            </div>
</div>
</div>
</div>
</div>
</body>
</html>

Mime
View raw message