Skip to content

Commit bbc7827

Browse files
author
Jesse Eichar
committed
Added docs about testing
1 parent d55f078 commit bbc7827

File tree

3 files changed

+37
-29
lines changed

3 files changed

+37
-29
lines changed

README.md

+31
Original file line numberDiff line numberDiff line change
@@ -411,3 +411,34 @@ Some resources for these annotations are:
411411
* http://minds.coremedia.com/2012/10/31/jsr-305-nonnull-and-guava-preconditions/
412412
* http://findbugs.sourceforge.net/manual/annotations.html (the package names are outof date
413413
and should be java.annotation instead of edu.umd.cs.findbugs.annotation but the descriptions are accurate)
414+
415+
# Testing
416+
417+
With regards to testing Geonetwork is a standard Java project and primarily depends on JUnit for testing. However there is a very important
418+
issue to consider when writing JUnit tests in Geonetwork and that is the separation between unit tests and integration tests
419+
420+
* *Unit Tests* - In Geonetwork unit tests should be very very quick to execute and not start up any subsystems of the application in order to keep
421+
the execution time of the unit tests very short. Integration tests do not require super classes and any assistance methods can be static
422+
imports, for example statically importing org.junit.Assert or org.junit.Assume or org.fao.geonet.Assert.
423+
* *Integration Tests* - Integration Test typically start much or all of Geonetwork as part of the test and will take longer to run than
424+
a unit test. However, even though the tests take longer they should still be implemented in such a way to be as efficient as possible.
425+
Starting Geonetwork in a way that isolates each integration test from each other integration test is non-trivial. Because of this
426+
there are `abstract` super classes to assist with this. Many modules have module specific Abstract classes. For example at the time
427+
that this is being written `domain`, `core`, `harvesters` and `services` modules all have module specific super classes that need to
428+
be used. (`harvesting` has 2 superclasses depending on what is to be tested.)
429+
The easiest way to learn how to implement an integration test is to search for other integration tests in the same module as the class
430+
you want to test. The following list provides a few tips:
431+
* *IMPORTANT*: All Integrations tests *must* end in IntegrationTest. The build system assumes all tests ending in IntegrationTest is
432+
an integration test and runs them in a build phase after unit tests. All other tests are assumed to be unit tests.
433+
* Prefer unit tests over Integration Tests because they are faster.
434+
* Search the current module for IntegrationTest to find tests to model your integration test against
435+
* This you might want integration tests for are:
436+
* Services: If the service already exists and you quick need to write a test to debug/fix its behaviour.
437+
If you are writing a new service it is better to use Mockito to mock the dependencies of the service so the test is
438+
a unit test.
439+
* Harvesters
440+
* A behaviour that crosses much of the full system
441+
442+
*org.fao.geonet.utils.GeonetHttpRequestFactory*: When making Http requests you should use org.fao.geonet.utils.GeonetHttpRequestFactory instead
443+
of directly using HttpClient. This is because there are mock instances of org.fao.geonet.utils.GeonetHttpRequestFactory that can
444+
be used to mock responses when performing tests.
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
package org.fao.geonet.test;
1+
package org.fao.geonet;
22

33
import java.util.Collection;
44

@@ -7,7 +7,7 @@
77
*
88
* @author heikki doeleman
99
*/
10-
public class GeonetworkTestCase extends junit.framework.TestCase {
10+
public final class Assert extends junit.framework.TestCase {
1111

1212
/**
1313
* Just to prevent junit.framework.AssertionFailedError: No tests found in org.fao.geonet.test.TestCase.
@@ -29,25 +29,4 @@ public static void assertContains(String msg, Object o, Collection<?> c) {
2929
}
3030
fail(msg);
3131
}
32-
33-
/**
34-
* No-arg constructor to enable serialization. This method is not intended to be used by mere mortals without
35-
* calling setName().
36-
*/
37-
public GeonetworkTestCase() {
38-
super();
39-
}
40-
/**
41-
* Constructs a test case with the given name.
42-
*/
43-
public GeonetworkTestCase(String name) {
44-
super(name);
45-
}
46-
/**
47-
* Sets the name of a TestCase.
48-
* @param name the name to set
49-
*/
50-
public void setName(String name) {
51-
super.setName(name);
52-
}
5332
}

core/src/test/java/org/fao/geonet/util/xml/NamespaceUtilsTest.java

+4-6
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
11
package org.fao.geonet.util.xml;
22

3+
import static org.fao.geonet.Assert.*;
34
import org.fao.geonet.utils.Xml;
4-
import org.fao.geonet.test.GeonetworkTestCase;
55
import org.jdom.Element;
66
import org.jdom.Namespace;
7+
import org.junit.Test;
78

89
import java.util.List;
910

@@ -14,12 +15,9 @@
1415
* @author heikki doeleman
1516
*
1617
*/
17-
public class NamespaceUtilsTest extends GeonetworkTestCase {
18-
19-
public NamespaceUtilsTest(String name) throws Exception {
20-
super(name);
21-
}
18+
public class NamespaceUtilsTest {
2219

20+
@Test
2321
public void testNamespaceInScope() throws Exception {
2422
String xml = "<?xml version=\"1.0\"?><root " +
2523
"xmlns:a=\"http://aaa\" " +

0 commit comments

Comments
 (0)