Page tree

The OpenSAML 2 software has reached its End of Life and is no longer supported. This documentation is available for historical purposes only.

Skip to end of metadata
Go to start of metadata

Testing Guide

OpenSAML 2, Java Edition, uses jUnit with the xmlUnit extension as its unit testing framework.

Test Source Layout

All of the source, configuration, and data files needed for unit tests are located in the src/test directory within the OpenSAML 2 source tree. Unit test classes should be located, in a package structure that mirrors the class being tested, in the src/test/java directory. For example, a unit test exercising the class org.opensaml.saml1.core.impl.ResponseMarshaller would be located in the directory src/test/java/org/opensaml/saml1/core/impl . Data files needed for the test are placed in the same package based directory but are rooted in the src/test/resources/data directory. Using the example above, test data files for ResponseMarshaller test would be located in src/test/resources/data/org/opensaml/saml1/core/impl . The src/test/resources directory also contains OpenSAML 2 configuration files used during tests.

Writing a Unit Test

All unit test cases must be named !XxxTest.java where Xxx is the name of the class being tested and should extend org.opensaml.common.BaseTestCase. Test method names, within the unit test, must be named testXxx where Xxx is some descriptive name for the test. For those familiar with jUnit, no TestSuite is necessary.

Extending BaseTestCase gives access to xmlUnit's assertion, the most useful of which is assertXMLEqual(Document, Document). This allows documents to be compared for equality (obviously). This is needed because serializing documents and doing string comparisons will normally fail because attributes can be in a different order in each case.

Executing the Tests

The standard maven command test will execute the unit tests.

Logging

Located directly under the src/test/resources directory is a logback configuration file used when testing.

  • No labels