Test Writing

As SquirrelJME is its own virtual machine implementation it uses its own testing system that is different from JUnit or TestNG however it is simple and suits the needs of the project. The main intention of the test framework is to allow for the testing on various virtual machines, since JUnit while it supports Java SE it does not support Java ME. So as such there will be some differences as to how tests are written along with their expectations.

Placement of Tests

Like standard Java tests, the tests are placed within the standard directory tree as like other Gradle projects:

Base Test Classes

All tests within SquirrelJME extend from one of the base classes that exist depending on what is needed for a test, all of these abstract classes are declared in net.multiphasicapps.tac:

Results And Expectations

One of the major differences is that SquirrelJME's test expectations are written in an expectations file rather than as something that exists in source code. The manifest itself is in the following format, the keys and values are specified later on in the document. Since there are virtual machine tests and the test framework uses the project's own implementation of the API there can be potential cases where a test may falsely pass because of some event or condition within the project that is erroneous. As such, since the results are elsewhere and static they are for the most part compared via string representation apart from some special conditions.

The manifest file is named the same as the test itself and is placed within the same package from within resources. The resources are accessed in the same manner as Class.getResourceAsStream(classBaseName) and as such is in the specific format:

result: NoResult
thrown: NoExceptionThrown
secondary-int--value: int:1234

The result is formed as part of the return value of a method, if there is one. thrown is any exception that is thrown from the test method. Any secondary value is set by using this.secondary(key, value) from a test, the result is stored for later checking. Secondary keys may be any value however they are dash encoded for special characters.

Printing Resultant Manifest

In the event a manifest needs to quickly be created there is a property which will print that manifest, this is generally used for getting the baseline results via Java SE. This should never be used outside of that, as running a test and placing in its own values normally is a very bad idea.

The following system property can be set:

Expectation Specifiers

The following expectation specifiers are used for various values. Arrays are specified by [length] and the values within are split by ,. Primitive type arrays may have the type followed by *, such as byte*[length], if they indicate that the array is of a boxed type, such as Byte[length] rather than byte[length] in Java.

Special specifiers for result and thrown are these:

The general value specifiers are:

String Encoding

For any <encodedString>, the characters are encoded as the following:

Secondary Key Encoding

The following characters map to the specified secondary key encoding:

Example

An example test with the test expectations:

// -*- Mode: Java; indent-tabs-mode: t; tab-width: 4 -*-
// ---------------------------------------------------------------------------
// SquirrelJME
//     Copyright (C) Stephanie Gawroriski <xer@multiphasicapps.net>
// ---------------------------------------------------------------------------
// SquirrelJME is under the Mozilla Public License Version 2.0.
// See license.mkd for licensing and copyright information.
// ---------------------------------------------------------------------------

package lang;

import net.multiphasicapps.tac.TestRunnable;

/**
 * Tests string trim.
 *
 * @since 2018/12/05
 */
public class TestStringTrim
	extends TestRunnable
{
	/**
	 * {@inheritDoc}
	 * @since 2018/12/05
	 */
	@Override
	public void test()
	{
		String cute = "squirrels are cute";
		
		this.secondary("a", cute.trim());
		this.secondary("b", "  \t      squirrels are cute".trim());
		this.secondary("c", "squirrels are cute    \t".trim());
		this.secondary("d", "       \tsquirrels are cute \t    ".trim());
		this.secondary("e", "           ".trim());
		this.secondary("f", "           ".trim());
		this.secondary("g", cute.trim());
	}
}
result: NoResult
thrown: NoExceptionThrown
secondary-a: string:squirrels\_are\_cute
secondary-b: string:squirrels\_are\_cute
secondary-c: string:squirrels\_are\_cute
secondary-d: string:squirrels\_are\_cute
secondary-e: string:
secondary-f: string:
secondary-g: string:squirrels\_are\_cute