A unit test is an elementary test discovered, run and reported by nitunit.

This class factorizes DocUnit and TestCase.

Introduced properties

private var _error: nullable String

nitc :: UnitTest :: _error

Error message occurred during test-case execution (or compilation).
private var _error_location: nullable Location

nitc :: UnitTest :: _error_location

The location where the error occurred, if it makes sense.
private var _info: nullable String

nitc :: UnitTest :: _info

Additional noteworthy information when a test success.
private var _is_done: Bool

nitc :: UnitTest :: _is_done

Flag that indicates if the unit test was compiled/run.
private var _raw_output: nullable String

nitc :: UnitTest :: _raw_output

The raw output of the execution (or compilation)
private var _real_time: Float

nitc :: UnitTest :: _real_time

Time for the execution, in seconds
private var _was_exec: Bool

nitc :: UnitTest :: _was_exec

Was the test case executed at least once?
fun error: nullable String

nitc :: UnitTest :: error

Error message occurred during test-case execution (or compilation).
fun error=(error: nullable String)

nitc :: UnitTest :: error=

Error message occurred during test-case execution (or compilation).
fun error_location: nullable Location

nitc :: UnitTest :: error_location

The location where the error occurred, if it makes sense.
fun error_location=(error_location: nullable Location)

nitc :: UnitTest :: error_location=

The location where the error occurred, if it makes sense.
abstract fun full_name: String

nitc :: UnitTest :: full_name

The name of the unit to show in messages
fun info: nullable String

nitc :: UnitTest :: info

Additional noteworthy information when a test success.
protected fun info=(info: nullable String)

nitc :: UnitTest :: info=

Additional noteworthy information when a test success.
fun is_done: Bool

nitc :: UnitTest :: is_done

Flag that indicates if the unit test was compiled/run.
fun is_done=(is_done: Bool)

nitc :: UnitTest :: is_done=

Flag that indicates if the unit test was compiled/run.
abstract fun location: Location

nitc :: UnitTest :: location

The location of the unit test to show in messages.
fun raw_output: nullable String

nitc :: UnitTest :: raw_output

The raw output of the execution (or compilation)
fun raw_output=(raw_output: nullable String)

nitc :: UnitTest :: raw_output=

The raw output of the execution (or compilation)
fun real_time: Float

nitc :: UnitTest :: real_time

Time for the execution, in seconds
fun real_time=(real_time: Float)

nitc :: UnitTest :: real_time=

Time for the execution, in seconds
fun status_tag(color: nullable Bool): String

nitc :: UnitTest :: status_tag

A colorful [OK] or [KO].
fun to_screen(more_message: nullable String, color: nullable Bool): String

nitc :: UnitTest :: to_screen

The full (color) description of the test-case.
fun to_xml: HTMLTag

nitc :: UnitTest :: to_xml

Return a <testcase> XML node in format compatible with Jenkins unit tests.
fun was_exec: Bool

nitc :: UnitTest :: was_exec

Was the test case executed at least once?
fun was_exec=(was_exec: Bool)

nitc :: UnitTest :: was_exec=

Was the test case executed at least once?
abstract fun xml_classname: String

nitc :: UnitTest :: xml_classname

The classname attribute of the XML format.
abstract fun xml_name: String

nitc :: UnitTest :: xml_name

The name attribute of the XML format.

Redefined properties

redef type SELF: UnitTest

nitc $ UnitTest :: SELF

Type of this instance, automatically specialized in every class

All properties

fun !=(other: nullable Object): Bool

core :: Object :: !=

Have self and other different values?
fun ==(other: nullable Object): Bool

core :: Object :: ==

Have self and other the same value?
type CLASS: Class[SELF]

core :: Object :: CLASS

The type of the class of self.
type SELF: Object

core :: Object :: SELF

Type of this instance, automatically specialized in every class
private var _error: nullable String

nitc :: UnitTest :: _error

Error message occurred during test-case execution (or compilation).
private var _error_location: nullable Location

nitc :: UnitTest :: _error_location

The location where the error occurred, if it makes sense.
private var _info: nullable String

nitc :: UnitTest :: _info

Additional noteworthy information when a test success.
private var _is_done: Bool

nitc :: UnitTest :: _is_done

Flag that indicates if the unit test was compiled/run.
private var _raw_output: nullable String

nitc :: UnitTest :: _raw_output

The raw output of the execution (or compilation)
private var _real_time: Float

nitc :: UnitTest :: _real_time

Time for the execution, in seconds
private var _was_exec: Bool

nitc :: UnitTest :: _was_exec

Was the test case executed at least once?
protected fun class_factory(name: String): CLASS

core :: Object :: class_factory

Implementation used by get_class to create the specific class.
fun class_name: String

core :: Object :: class_name

The class name of the object.
fun error: nullable String

nitc :: UnitTest :: error

Error message occurred during test-case execution (or compilation).
fun error=(error: nullable String)

nitc :: UnitTest :: error=

Error message occurred during test-case execution (or compilation).
fun error_location: nullable Location

nitc :: UnitTest :: error_location

The location where the error occurred, if it makes sense.
fun error_location=(error_location: nullable Location)

nitc :: UnitTest :: error_location=

The location where the error occurred, if it makes sense.
abstract fun full_name: String

nitc :: UnitTest :: full_name

The name of the unit to show in messages
fun get_class: CLASS

core :: Object :: get_class

The meta-object representing the dynamic type of self.
fun hash: Int

core :: Object :: hash

The hash code of the object.
fun info: nullable String

nitc :: UnitTest :: info

Additional noteworthy information when a test success.
protected fun info=(info: nullable String)

nitc :: UnitTest :: info=

Additional noteworthy information when a test success.
init init

core :: Object :: init

fun inspect: String

core :: Object :: inspect

Developer readable representation of self.
protected fun inspect_head: String

core :: Object :: inspect_head

Return "CLASSNAME:#OBJECTID".
fun is_done: Bool

nitc :: UnitTest :: is_done

Flag that indicates if the unit test was compiled/run.
fun is_done=(is_done: Bool)

nitc :: UnitTest :: is_done=

Flag that indicates if the unit test was compiled/run.
intern fun is_same_instance(other: nullable Object): Bool

core :: Object :: is_same_instance

Return true if self and other are the same instance (i.e. same identity).
fun is_same_serialized(other: nullable Object): Bool

core :: Object :: is_same_serialized

Is self the same as other in a serialization context?
intern fun is_same_type(other: Object): Bool

core :: Object :: is_same_type

Return true if self and other have the same dynamic type.
abstract fun location: Location

nitc :: UnitTest :: location

The location of the unit test to show in messages.
private intern fun native_class_name: CString

core :: Object :: native_class_name

The class name of the object in CString format.
intern fun object_id: Int

core :: Object :: object_id

An internal hash code for the object based on its identity.
fun output

core :: Object :: output

Display self on stdout (debug only).
intern fun output_class_name

core :: Object :: output_class_name

Display class name on stdout (debug only).
fun raw_output: nullable String

nitc :: UnitTest :: raw_output

The raw output of the execution (or compilation)
fun raw_output=(raw_output: nullable String)

nitc :: UnitTest :: raw_output=

The raw output of the execution (or compilation)
fun real_time: Float

nitc :: UnitTest :: real_time

Time for the execution, in seconds
fun real_time=(real_time: Float)

nitc :: UnitTest :: real_time=

Time for the execution, in seconds
fun serialization_hash: Int

core :: Object :: serialization_hash

Hash value use for serialization
fun status_tag(color: nullable Bool): String

nitc :: UnitTest :: status_tag

A colorful [OK] or [KO].
intern fun sys: Sys

core :: Object :: sys

Return the global sys object, the only instance of the Sys class.
abstract fun to_jvalue(env: JniEnv): JValue

core :: Object :: to_jvalue

fun to_s: String

core :: Object :: to_s

User readable representation of self.
fun to_screen(more_message: nullable String, color: nullable Bool): String

nitc :: UnitTest :: to_screen

The full (color) description of the test-case.
fun to_xml: HTMLTag

nitc :: UnitTest :: to_xml

Return a <testcase> XML node in format compatible with Jenkins unit tests.
fun was_exec: Bool

nitc :: UnitTest :: was_exec

Was the test case executed at least once?
fun was_exec=(was_exec: Bool)

nitc :: UnitTest :: was_exec=

Was the test case executed at least once?
abstract fun xml_classname: String

nitc :: UnitTest :: xml_classname

The classname attribute of the XML format.
abstract fun xml_name: String

nitc :: UnitTest :: xml_name

The name attribute of the XML format.
package_diagram nitc::UnitTest UnitTest core::Object Object nitc::UnitTest->core::Object nitc::DocUnit DocUnit nitc::DocUnit->nitc::UnitTest nitc::TestCase TestCase nitc::TestCase->nitc::UnitTest

Parents

interface Object

core :: Object

The root of the class hierarchy.

Children

class DocUnit

nitc :: DocUnit

A unit-test extracted from some documentation.
class TestCase

nitc :: TestCase

A test case is a unit test considering only a MMethodDef.

Class definitions

nitc $ UnitTest
# A unit test is an elementary test discovered, run and reported by nitunit.
#
# This class factorizes `DocUnit` and `TestCase`.
abstract class UnitTest
	# The name of the unit to show in messages
	fun full_name: String is abstract

	# The location of the unit test to show in messages.
	fun location: Location is abstract

	# Flag that indicates if the unit test was compiled/run.
	var is_done: Bool = false is writable

	# Error message occurred during test-case execution (or compilation).
	#
	# e.g.: `Runtime Error`
	var error: nullable String = null is writable

	# Was the test case executed at least once?
	#
	# This will indicate the status of the test (failture or error)
	var was_exec = false is writable

	# The raw output of the execution (or compilation)
	#
	# It merges the standard output and error output
	var raw_output: nullable String = null is writable

	# The location where the error occurred, if it makes sense.
	var error_location: nullable Location = null is writable

	# Additional noteworthy information when a test success.
	var info: nullable String = null

	# Time for the execution, in seconds
	var real_time: Float = 0.0 is writable

	# A colorful `[OK]` or `[KO]`.
	fun status_tag(color: nullable Bool): String do
		color = color or else true
		if not is_done then
			return "[  ]"
		else if error != null then
			var res = "[KO]"
			if color then res = res.red.bold
			return res
		else
			var res = "[OK]"
			if color then res = res.green.bold
			return res
		end
	end

	# The full (color) description of the test-case.
	#
	# `more message`, if any, is added after the error message.
	fun to_screen(more_message: nullable String, color: nullable Bool): String do
		color = color or else true
		var res
		var error = self.error
		if error != null then
			if more_message != null then error += " " + more_message
			var loc = error_location or else location
			if color then
				res = "{status_tag(color)} {full_name}\n     {loc.to_s.yellow}: {error}\n{loc.colored_line("1;31")}"
			else
				res = "{status_tag(color)} {full_name}\n     {loc}: {error}"
			end
			var output = self.raw_output
			if output != null then
				res += "\n     Output\n\t{output.chomp.replace("\n", "\n\t")}\n"
			end
		else
			res = "{status_tag(color)} {full_name}"
			if more_message != null then res += more_message
			var info = self.info
			if info != null then
				res += "\n     {info}"
			end
		end
		return res
	end

	# Return a `<testcase>` XML node in format compatible with Jenkins unit tests.
	fun to_xml: HTMLTag do
		var tc = new HTMLTag("testcase")
		tc.attr("classname", xml_classname)
		tc.attr("name", xml_name)
		tc.attr("time", real_time.to_s)

		var output = self.raw_output
		if output != null then output = output.trunc(8192).filter_nonprintable
		var error = self.error
		if error != null then
			var node
			if was_exec then
				node = tc.open("error").attr("message", error)
			else
				node = tc.open("failure").attr("message", error)
			end
			if output != null then
				node.append(output)
			end
		else if output != null then
			tc.open("system-err").append(output)
		end
		return tc
	end

	# The `classname` attribute of the XML format.
	#
	# NOTE: jenkins expects a '.' in the classname attr
	#
	# See to_xml
	fun xml_classname: String is abstract

	# The `name` attribute of the XML format.
	#
	# See to_xml
	fun xml_name: String is abstract
end
src/testing/testing_base.nit:178,1--298,3