The information on these pages may be out of date, or may refer to
resources that have moved or have been made read-only.
For more information please refer to the
Apache Attic
The framework for testing serialization is currently PROPOSED and being
discussed on the development mailing list dev@harmony.apache.org
.
Please direct comments and questions there.
The framework for testing serialization is intended to simplify and formalize development of serialization tests. This document contains guidelines for creating tests and conventions for resource files.
The testing framework provides the support class
org.apache.harmony.testframework.serialization.SerializationTest
for serialization testing.
Verifies that an object serialized on certified implementation is
correctly deserialized on Harmony implementation.
The support class provides four methods for compatibility testing:
- verifyGolden(TestCase, Object)
-
verifyGolden(TestCase, Object, SerializableAssert)
- verifyGolden(TestCase, Object[])
-
verifyGolden(TestCase, Object[], SerializableAssert)
The first parameter TestCase
is used to locate resource
file(s) that contains serialized object(s).
The second parameter is an object
or an array of objects to be compared with object(s) deserialized from
resource file(s).
The third parameter is optional.
To create a compatibility test for selected class, a developer should:
testSerializationCompatibility
method to a unit test
Example
public void testSerializationCompatibility() throws Exception { SerializationTest.verifyGolden(this, new SomeSerializableClass()); }
Verifies that an object can be smoothly serialized and deserialized on
Harmony implementation.
The support class provides four methods for self-testing:
- verifySelf(Object)
-
verifySelf(Object, SerializableAssert)
- verifySelf(Object[])
-
verifySelf(Object[], SerializableAssert)
The provided object(s) is(are) serialized/deserialized and compared with initial object(s).
To create a self test for a selected class, a developer should:
testSerializationSelf
method to a unit test
Example
public void testSerializationSelf() throws Exception { SerializationTest.verifySelf(new SomeSerializableClass(), new MyComparator()); }
Interface
SerializableAssert
If a class of object(s) to be compared does not have equals(Object) method or the testing framework can not find appropriate comparator, a test has to implement the interface. The interface has only one method to be implemented:
void assertDeserialized(Serializable reference, Serializable test);
The resource files should follow the next conventions:
<module root>/src/test/resources/serialization
<golden>
keyword is used for files generated on RI
<harmony>
keyword is used for files generated on
Harmony implementation
<negative>
keyword is used for files that contain
broken serial form
Note
If only one file exists, the index is not required.
ser
Example
For the test org.apache.harmony.tests.java.lang.SomeClassTest
,
we have the following resource files:
modules/luni/src/test/resources/serialization | \---org/apache/harmony/tests/java/lang | \---SomeClassTest.golden.0.ser SomeClassTest.golden.1.ser SomeClassTest.golden.2.ser SomeClassTest.harmony.0.ser SomeClassTest.harmony.1.ser SomeClassTest.negative.ser