Skip to content
This repository has been archived by the owner on Aug 13, 2024. It is now read-only.
/ Unit2 Public archive

A modification of the original haXe's unit testing framework

Notifications You must be signed in to change notification settings

njuneau/Unit2

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

27 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Unit2 Test framework

Description

This is a modification of Haxe's unit testing framework. Unit2 makes use of class metadata in its test runners instead of relying on method names in order to detect test methods. It is inspired by JUnit's way of working.

Unit2 also redefines how the test results are written out. Unit2 makes use of "output writers" that lets the user easily implement his own way of outputting the test results. For example, one might define an output writer that writes HTML instead of plain text.

The assertion mechanism has also changed. Unit2 lets the TestRunner manage errors - hence, any status management is moved out of the TestCase class. Assertions now throw exceptions that can be caught by the TestRunner in order to detect errors.

How to use

Including in your projects

For the latest release, install the unit2 library through haxelib:

haxelib install unit2 1.0.0-beta.1

And include the following in your HXML files:

-lib unit2

Writing a simple test suite

Start by creating a class that extends unit2.TestCase. This class will hold your test case's unit tests. Add the @Test metadata tag to every method you want executed by the test runner as a test.

You may also use the @Before and @After tags to annotate methods that will be executed, respectively, before and after each test method. The can only be one of each.

You may also use the @BeforeClass and @AfterClass tags to annotate methods that will be executed, respectively, before and after all the tests methods are ran (in a constructor/destructor fashion).

Once your test case is ready, create a new TestRunner instance and add your test case class into it. Once you added all your test cases, run the test runner.

Once the test runner has finished running, you can use an OutputWriter to view the results. Unit2 ships with a default text-based OutputWriter. Create a unit2.output.TextOutputWriter instance and execute the writeResults method with your test runner as a parameter. This will return a text formatted test report. You are free to output that string in the way you want. For example, you can print it in the console, trace it or even display a Web page with the results in it.

Copyright information

Some of the framework's files were taken directly from Haxe 2's source code. Although these files are now modified, they retain the copyright notices of the original files.

About

A modification of the original haXe's unit testing framework

Resources

Stars

Watchers

Forks

Packages

No packages published