|
|
||
Gregg Sporar's BloguPortal Development, Part 4Posted by gsporar on February 27, 2006 at 09:06 PM | Comments (0)Part 3 of this series explained the steps needed to setup a free-form project like uPortal for debugging. Similar steps are needed in order to be able to use the IDE's JUnit support. There are two objectives:
1. Setup Compilation of a Single FileIn order to be able to compile a single file, the IDE needs to know which file has been selected. As with adding support for the debugger, the IDE provides some help with setting up the correct targets.
2. Running A Single JUnit TestRunning a single JUnit test requires a target that will execute JUnit for the currently selected file. Copy and paste this target into ide-file-targets.xml:
<target name="test-selected-file">
<fail unless="file">Must set property 'file'</fail>
<junit fork="true" printsummary="on" showoutput="on" dir=".." >
<classpath>
<pathelement path="build/WEB-INF/classes"/>
<path refid="tests.classpath"/>
<path location="build/WEB-INF/classes"/>
</classpath>
<formatter usefile="false" type="brief"/>
<formatter type="xml"/>
<test name="${file}">
</test>
</junit>
</target>
And then at the top of the file, add an import of build.xml:<import file="../build.xml"/> The next step is to modify the project.xml file that is in the /nbproject folder. Add this entry to it:
<action name="test.single">
<script>nbproject/ide-file-targets.xml</script>
<target>test-selected-file</target>
<context>
<property>file</property>
<folder>tests</folder>
<pattern>\.java$</pattern>
<format>java-name</format>
<arity>
<one-file-only/>
</arity>
</context>
</action>
After saving the changes, you should be able to select a single JUnit test in
the Projects window (for example, ChannelDefinitionTest.java)
and then select Run > Run File > Test (file name) - or
you can just press Ctrl-F6 and see nicely formatted JUnit
output results.
3. Running All JUnit TestsThe uPortal Quickstart's build.xml already has a target that will run all JUnit tests: runtests. That target will work fine in the NetBeans IDE, but the output is less than inspiring: it's just regular text. To see it, right-click the uPortal entry in the Projects window and then select Test Project. That output would look better in the JUnit output window that the IDE provides, but in order for an Ant build target to use it, the target must meet these requirements. There are two options for meeting those requirements: modify the build.xml (probably not a good idea) or create a new custom Ant target that is only for use by the IDE. The easiest way to create a custom Ant target is to add it to the ide-targets.xml file that is in the nbproject folder. Copy and paste this target into ide-targets.xml:
<target name="run-tests" depends="compiletests" description="Run JUnit Test Suite">
<junit fork="true" printsummary="on" showoutput="on" dir=".." >
<classpath>
<pathelement path="${build.home}/WEB-INF/classes"/>
<path refid="tests.classpath"/>
<path location="${build.home}/WEB-INF/classes"/>
</classpath>
<formatter usefile="false" type="brief"/>
<formatter type="xml"/>
<batchtest>
<fileset dir="${build.home}/WEB-INF/classes">
<include name="**/*Test.class"/>
<exclude name="**/Abstract*Test.class"/>
<exclude name="**/*AbstractTest.class"/>
<exclude name="**/DbTest.class"/>
</fileset>
</batchtest>
</junit>
</target>
Since this target is dependent on the compiletests target that
is defined in build.xml, the ide-targets.xml file must also be
modified to add this line:<import file="../build.xml"/> The last step is to modify the project.xml file that is in the /nbproject folder. It currently specifies that the runtests target in build.xml should be invoked when Test Project is selected:
After those changes are in place, right-click the entry for uPortal in the Projects window and choose Test Project again. The output is much more helpful:
Bookmark blog post: CommentsComments are listed in date ascending order (oldest first) | Post Comment | ||
|
|