The Android test framework is based on JUnit, so some classes that are not related to the platform can be tested directly using the testcase in JUnit.
Morsecodeconvertertest is used to test morsecodeconverter classes, Morsecodeconverter implementations are not connected to the Android platform, so you can use testcase directly as a base class.
TestCase is derived from the Assert class, Assert provides a large number of assert methods to compare expected and actual values.
This example code is as follows:
public class Morsecodeconvertertest extends TestCase {
@SmallTest public
void Testcharacters () throws Exception {
long[] expectedbeeps = {
Morsecodeconverter.dot,
Morsecodeconverter.dot,
Morsecodeconverter.dot ,
Morsecodeconverter.dot,
Morsecodeconverter.dot};
long[] beeps = Morsecodeconverter.pattern (' s ');
Assertarraysequal (expectedbeeps, beeps);
}
private void Assertarraysequal (long[] expected, long[] actual) {
assertequals ("unexpected array length.",
Expected.length, actual.length);
for (int i = 0; i < expected.length i++) {
long expectedlong = expected[i];
Long Actuallong = Actual[i];
Assertequals ("Unexpected Long at index:" + I,
expectedlong, Actuallong);}}
For a basic JUnit Testcase test, use assertequals to test expected and actual values.
See a full set of tutorials: http://www.bianceng.cn/OS/extra/201301/35252.htm