1 |
4523
|
daigle
|
<!--
|
2 |
|
|
* sitemaps.html
|
3 |
|
|
*
|
4 |
|
|
* Authors: Michael Daigle
|
5 |
|
|
* Copyright: 2008 Regents of the University of California and the
|
6 |
|
|
* National Center for Ecological Analysis and Synthesis
|
7 |
|
|
* For Details: http://www.nceas.ucsb.edu/
|
8 |
|
|
* Created: 2008 November 4
|
9 |
|
|
* Version:
|
10 |
|
|
* File Info: '$ '
|
11 |
|
|
*
|
12 |
|
|
*
|
13 |
|
|
-->
|
14 |
|
|
<HTML>
|
15 |
|
|
<HEAD>
|
16 |
|
|
<TITLE>Testing Metacat</TITLE>
|
17 |
4528
|
daigle
|
<!-- unfortunately, we have to look for the common css file in the
|
18 |
|
|
user docs directory. This is because the user docs deploy to
|
19 |
|
|
the top level of the metacat docs on the knb web server -->
|
20 |
|
|
<link rel="stylesheet" type="text/css" href="../user/common.css">
|
21 |
4523
|
daigle
|
<link rel="stylesheet" type="text/css" href="./default.css">
|
22 |
|
|
</HEAD>
|
23 |
|
|
<BODY>
|
24 |
|
|
<table width="100%">
|
25 |
|
|
<tr>
|
26 |
|
|
<td class="tablehead" colspan="2"><p class="label">Testing Metacat</p></td>
|
27 |
|
|
<td class="tablehead" colspan="2" align="right">
|
28 |
4528
|
daigle
|
<a href="./metacat-eclipse-project.html">Back</a> | <a href="./index.html">Home</a> |
|
29 |
|
|
<!--a href="add next file here when one exists" -->Next<!-- /a -->
|
30 |
4523
|
daigle
|
</td>
|
31 |
|
|
</tr>
|
32 |
|
|
</table>
|
33 |
|
|
|
34 |
|
|
<div class="header1">Table of Contents</div>
|
35 |
|
|
<div class="toc">
|
36 |
|
|
<div class="toc1"><a href="#Intro">About Metacat Testing</a></div>
|
37 |
|
|
<div class="toc2"><a href="#Overview">Overview</a></div>
|
38 |
|
|
<div class="toc2"><a href="#MetacatImplementation">JUnit Implementation in Metacat</a></div>
|
39 |
|
|
<div class="toc1"><a href="#WritingTestCase">Writing a Test Case</a></div>
|
40 |
|
|
<div class="toc2"><a href="#Basics">Basics</a></div>
|
41 |
|
|
<div class="toc2"><a href="#MCTestCase">MCTestCase Base Class</a></div>
|
42 |
|
|
<div class="toc2"><a href="#BestPractices">Best Practices</a></div>
|
43 |
|
|
<div class="toc1"><a href="#RunTests">Running Test Cases</a></div>
|
44 |
|
|
<div class="toc2"><a href="#AntTask">Ant task</a></div>
|
45 |
|
|
<div class="toc2"><a href="#ConfigureMetacat">Configure Metacat For Testing</a></div>
|
46 |
|
|
<div class="toc2"><a href="#RunAllTests">Run All Tests</a></div>
|
47 |
|
|
<div class="toc2"><a href="#RunOneTest">Run One Test</a></div>
|
48 |
|
|
<div class="toc2"><a href="#ViewingOutput">Viewing Test Output</a></div>
|
49 |
|
|
</div>
|
50 |
|
|
|
51 |
|
|
<a name="Intro"></a><div class="header1">About Metacat Testing</div>
|
52 |
|
|
<a name="Overview"></a><div class="header2">Overview</div>
|
53 |
|
|
<p>Metacat uses JUnit tests to test its core functionality. These tests are
|
54 |
|
|
good for testing the internal workings of an application, but don't test the
|
55 |
|
|
layout and appearance. JUnit tests are meant to be one tool in the developer's
|
56 |
|
|
test arsinal. If you are not familiar with JUnit, you should search out some
|
57 |
|
|
tutorial documentation online. One such tutorial is at
|
58 |
|
|
<a href="http://clarkware.com/articles/JUnitPrimer.html"> The Clarkware JUnit primer</a></p>
|
59 |
|
|
|
60 |
|
|
<p>Metacat test cases will need to be run on the same server as the Metacat
|
61 |
|
|
instance that you want to test. Since Metacat and its test cases share the same
|
62 |
|
|
configuration files, there is no way to run the tests remotely.</p>
|
63 |
|
|
|
64 |
|
|
<a name="MetacatImplementation"></a><div class="header2">JUnit Implementation in Metacat</div>
|
65 |
|
|
<p>Metacat test cases are located in the code at:
|
66 |
|
|
<div class="code"><workspace>/metacat/test/edu/ucsb/nceas/metacat*/</div>
|
67 |
|
|
There you will find several java files that define JUnit tests.</p>
|
68 |
|
|
|
69 |
|
|
<p> Test cases are run via an ant task, and output from the tests appears in
|
70 |
|
|
a build directory. More on this to follow.</p>
|
71 |
|
|
|
72 |
|
|
<a name="WritingTestCase"></a><div class="header1">Writing a Test Case</div>
|
73 |
|
|
<a name="Basics"></a><div class="header2">Basics</div>
|
74 |
|
|
<p>All you need to do to get your JUnit test included into the Metacat test
|
75 |
|
|
suite is to create it in one of the <workspace>/test/edu/ucsb/nceas/metacat*/
|
76 |
|
|
directories. The ant test tasks will know that it should be run. </p>
|
77 |
|
|
|
78 |
|
|
<p> The following methods are required in a test case class:
|
79 |
|
|
<ul>
|
80 |
|
|
<li>public <Constructor>(String name) - The constructor for the test class. </li>
|
81 |
|
|
<li>public void setUp() - Set up any dependencies for the tests. This is run before each test case.</li>
|
82 |
|
|
<li>public void tearDown() - Release an resources used by the test.</li>
|
83 |
|
|
<li>public static Test suite() - define the test methods that need to be run.</li>
|
84 |
|
|
<li>public void initialize() - define any global initializations that need to be done.</li>
|
85 |
|
|
</ul>
|
86 |
|
|
|
87 |
|
|
You will test for failure using the many assertion methods available.</p>
|
88 |
|
|
|
89 |
|
|
<a name="MCTestCase"></a><div class="header2">MCTestCase Base Class</div>
|
90 |
|
|
<p>Metacat test cases extend the MCTestCase base class, which holds common
|
91 |
|
|
methods and variables. Some of these include:
|
92 |
|
|
<ul>
|
93 |
|
|
<li>SUCCESS/FALURE - boolean variables holding the values for success and failure. </li>
|
94 |
|
|
<li>metacatUrl, username, password - connection variables used for LDAP connectivity</li>
|
95 |
|
|
<li>readDocumentIdWhichEqualsDoc() - method to read a document from Metacat server.</li>
|
96 |
|
|
<li>debug() - method to display debug output to standard error.</li>
|
97 |
|
|
</ul>
|
98 |
|
|
These are just a few examples to give you an idea of what is in MCTestCase.
|
99 |
|
|
</p>
|
100 |
|
|
|
101 |
|
|
<a name="BestPractices"></a><div class="header2">Best Practices</div>
|
102 |
|
|
<p>The following are a few best practices when writing test cases:
|
103 |
|
|
<ul>
|
104 |
|
|
<li>Extend MCTestCase - Although strictly speaking, it is possible to bypass MCTestCase
|
105 |
|
|
and just extend the JUnit TestCase class, you should not do so. You should always
|
106 |
|
|
extend the MCTestCase class.</li>
|
107 |
|
|
<li>Extend Multiple Test Methods - Try to strike a balance between the number of test
|
108 |
|
|
methods and the size of each test. If a test method starts to get huge, you might see
|
109 |
|
|
if you can break it down into mulitple tests based on functionality. If the number of
|
110 |
|
|
tests in the test suite starts to get large, you might see if it makes sense to
|
111 |
|
|
separate them out into different test classes.</li>
|
112 |
|
|
<li>Use assertion message - Most assertion methods have an alternate implementation that
|
113 |
|
|
includes a message parameter. This message will be shown if the assertion fails. You
|
114 |
|
|
should use this version of the assertion method.</li>
|
115 |
|
|
<li>debug() - You should use the debug() method available in the MCTestCase class to
|
116 |
|
|
display debug output as opposed to System.err.println(). The test configuration will
|
117 |
|
|
allow you to turn off debug output when you use the debug() method.</li>
|
118 |
|
|
</ul>
|
119 |
|
|
|
120 |
|
|
<a name="RunTests"></a><div class="header1">Running Test Cases</div>
|
121 |
|
|
<a name="AntTask"></a><div class="header2">Ant task</div>
|
122 |
|
|
<p>As we discussed earlier, the test cases run from within ant tasks. There is a
|
123 |
|
|
task to run all tests and a task to run individual tests. </p>
|
124 |
|
|
<p>You will need to have ant installed on your system. For downloads and instructions,
|
125 |
|
|
visit the <a href="http://ant.apache.org/">Apache Ant site</a>.
|
126 |
|
|
</p>
|
127 |
|
|
<a name="ConfigureMetacat"></a><div class="header2">Configure Metacat For Testing</div>
|
128 |
|
|
<p>The test cases will look at the server's metacat properties file for configuration,
|
129 |
|
|
so there are two places that need to be configured.</p>
|
130 |
|
|
<p>First, you need to edit the configuration file at:
|
131 |
|
|
<div class="code"><workspace>/metacat/test/test.properties</div>
|
132 |
|
|
This should only hold one property: metacat.contextDir. This should point to
|
133 |
|
|
the context directory for the metacat server you are testing. For example:
|
134 |
|
|
<div class="code">metacat.contextDir=/usr/share/tomcat5.5/webapps/knb</div>
|
135 |
|
|
The test classes will use this to determine where to look for the server
|
136 |
|
|
metacat.properties file.</p>
|
137 |
|
|
|
138 |
|
|
<p>the remainder of the configuration needs to happen in the actual server's
|
139 |
|
|
metacat.properties file located at:
|
140 |
|
|
<div class="code"><workspace>/metacat/lib/metacat.properties</div>
|
141 |
4526
|
daigle
|
You will need to verify that all test.* properties are set correctly:
|
142 |
4523
|
daigle
|
<ul>
|
143 |
|
|
<li>test.printdebug - true if you want debug output, false otherwise </li>
|
144 |
|
|
<li>test.metacatUrl - the url for the metacat servlet (i.e. http://localhost:8080/knb/metacat)</li>
|
145 |
|
|
<li>test.contextUrl - the url for the metacat web service (i.e. http://localhost:8080/knb)</li>
|
146 |
|
|
<li>test.metacatDeployDir - the directory where metacat is physically deployed (i.e. /usr/local/tomcat/webapps/knb)</li>
|
147 |
|
|
<li>test.mcUser - the first metacat test user ("uid=kepler,o=unaffiliated,dc=ecoinformatics,dc=org" should be fine)</li>
|
148 |
|
|
<li>test.mcPassword - the first metacat test password ("kepler" should be fine)</li>
|
149 |
|
|
<li>test.mcAnotherUser - the second metacat test user. This user must be a member of the knb-usr
|
150 |
|
|
group in ldap. ("uid=test,o=NCEAS,dc=ecoinformatics,dc=org" should be fine)</li>
|
151 |
|
|
<li>test.mcAnotherPassword - the second metacat test password ("test" should be fine)</li>
|
152 |
|
|
<li>test.piscoUser - the pisco test user ("uid=piscotest,o=PISCO,dc=ecoinformatics,dc=org" should be fine)</li>
|
153 |
|
|
<li>test.piscoPassword - the pisco test password ("testPW" should be fine)</li>
|
154 |
|
|
<li>test.lterUser - the lter test user ("uid=tmonkey,o=LTER,dc=ecoinformatics,dc=org" should be fine)</li>
|
155 |
|
|
<li>test.lterPassword - the lter test password ("T3$tusr" should be fine)</li>
|
156 |
|
|
<li>test.testProperty - a property to verify that we can read properties (leave as "testing")</li>
|
157 |
|
|
</ul>
|
158 |
|
|
</p>
|
159 |
|
|
|
160 |
|
|
<p>Note that none of the test users should also be administrative users. This will mess up
|
161 |
|
|
the access tests since some document modifications will succeed when we expect them to fail.</p>
|
162 |
|
|
|
163 |
|
|
<p>Once this is done, you will need to rebuild and redeploy the Metacat server. Note that
|
164 |
|
|
changing these properties does nothing to change the way the Metacat server runs. Rebuilding
|
165 |
|
|
and redeploying merely makes the test properties available to the JUnit tests.</p>
|
166 |
|
|
|
167 |
|
|
<a name="RunAllTests"></a><div class="header2">Run All Tests</div>
|
168 |
|
|
<p>To run all tests, go to the <workspace>/metacat directory and type</p>
|
169 |
|
|
<div class="code">ant clean test</div>
|
170 |
|
|
You will see a line to standard output summarizing each test result.
|
171 |
|
|
</p>
|
172 |
|
|
|
173 |
|
|
<a name="RunOneTest"></a><div class="header2">Run One Test</div>
|
174 |
|
|
<p>To run one test, go to the <workspace>/metacat directory and type</p>
|
175 |
|
|
<div class="code">ant clean runonetest -Dtesttorun=<test_name></div>
|
176 |
|
|
Where <test_name> is the name of the JUnit test class (without .java on
|
177 |
|
|
the end). You will see debug information print to standard error.
|
178 |
|
|
</p>
|
179 |
|
|
|
180 |
|
|
<a name="ViewingOutput"></a><div class="header2">Viewing Test Output</div>
|
181 |
|
|
<p>Regardless of whether you ran one test or all tests, you will see output in
|
182 |
|
|
the Metacat build directory in your code at:
|
183 |
|
|
<div class="code"><workspace>/metacat/build</div>
|
184 |
|
|
There will be one output file for each test class. The files will look like
|
185 |
|
|
<div class="code">TEST-edu.ucsb.nceas.<test_dir>.<test_name>.txt</div>
|
186 |
|
|
where <test_dir> is the metacat* directory where the test lives and
|
187 |
|
|
<test_name> is the name of the JUnit test class. These output files will have
|
188 |
|
|
all standard error and standard out output as well as information on assertion
|
189 |
|
|
failures in the event of a failed test.
|
190 |
|
|
</p>
|
191 |
|
|
|
192 |
|
|
<br>
|
193 |
4528
|
daigle
|
<a href="./metacat-eclipse-project.html">Back</a> | <a href="./index.html">Home</a> |
|
194 |
|
|
<!--a href="add next file here when one exists" -->Next<!-- /a -->
|
195 |
4523
|
daigle
|
</ul>
|
196 |
|
|
|
197 |
|
|
</BODY>
|
198 |
|
|
</HTML>
|