WoW WoWUnit addon Dragonflight/Wrath of the Lich King Classic 2024
logo
wow addon WoWUnit

WoWUnit

Game Version: 6.0.3
Total Downloads: 4,056
Updated: Nov 20, 2014
Created: Jan 24, 2009
download WoWUnitDownload Earlier Versions

Earlier Versions

Name Size Uploaded Game Version Downloads
1.1.21 release 6.67 KB Nov 20, 2014 6.0.3 817 download WoWUnit 1.1.21 releaseDownload
1.1.14 release 5.98 KB Oct 13, 2010 4.0.1 972 download WoWUnit 1.1.14 releaseDownload
1.0.9 release 4.60 KB Feb 7, 2009 3.0.8 911 download WoWUnit 1.0.9 releaseDownload
1.0.6 release 4.33 KB Feb 7, 2009 3.0.8 266 download WoWUnit 1.0.6 releaseDownload
1.0.4 release 4.00 KB Feb 7, 2009 3.0.8 222 download WoWUnit 1.0.4 releaseDownload
1.0 release 3.90 KB Jan 27, 2009 3.0.8 284 download WoWUnit 1.0 releaseDownload
r21 alpha 6.62 KB Nov 20, 2014 6.0.3 61 download WoWUnit r21 alphaDownload
r20 alpha 6.80 KB Aug 9, 2012 5.0.4 66 download WoWUnit r20 alphaDownload
r19 alpha 5.94 KB Aug 7, 2012 5.0.4 31 download WoWUnit r19 alphaDownload
r18 alpha 6.16 KB Oct 31, 2010 4.0.1 75 download WoWUnit r18 alphaDownload
r17 alpha 5.99 KB Oct 27, 2010 4.0.1 50 download WoWUnit r17 alphaDownload
r16 alpha 5.89 KB Oct 27, 2010 4.0.1 47 download WoWUnit r16 alphaDownload
r14 alpha 5.92 KB Oct 2, 2010 4.0.1 36 download WoWUnit r14 alphaDownload
r13 alpha 5.84 KB Sep 23, 2010 4.0.1 41 download WoWUnit r13 alphaDownload
r12 alpha 4.29 KB Jul 6, 2009 3.1.0 42 download WoWUnit r12 alphaDownload
r11 alpha 4.19 KB Apr 14, 2009 3.1.0 25 download WoWUnit r11 alphaDownload
r9 alpha 4.55 KB Feb 7, 2009 3.0.8 40 download WoWUnit r9 alphaDownload
r8 alpha 4.45 KB Feb 7, 2009 3.0.8 17 download WoWUnit r8 alphaDownload
r6 alpha 4.28 KB Feb 7, 2009 3.0.8 21 download WoWUnit r6 alphaDownload
r4 alpha 3.96 KB Feb 7, 2009 3.0.8 16 download WoWUnit r4 alphaDownload
r2 alpha 3.87 KB Jan 27, 2009 3.0.8 16 download WoWUnit r2 alphaDownload

Description

Share this:

WoWUnit is a unit testing framework for addon developers to use when creating addons.

What is Unit Testing?

(quoted from Wikipedia: http://en.wikipedia.org/wiki/Unit_testing)
In computer programming, unit testing is a method of testing that verifies the individual units of source code are working properly. A unit is the smallest testable part of an application. In procedural programming a unit may be an individual program, function, procedure, etc., while in object-oriented programming, the smallest unit is a method, which may belong to a base/super class, abstract class or derived/child class.

Features

WoWUnit contains the following features:

  • Allows addon developers to create and execute test suites.
  • Allows WoW API calls to be simulated by allowing the developer to create mock functions that override API calls during the tests.
  • Set up and tear down methods in the test suite can be used to define a consistent context in which tests are run.
  • Enables regression testing by helping to ensure that finished pieces of code are broken by a recent change.
  • Console based user interface that doesn't get in the way any addons being developed.

Usage

Developers should first make WoWUnit an optional dependency for their addon. They can then create a test suite and register the suite with WoWUnit. Test suites can be run by typing "/wowunit <test suite>" at the console. WoWUnit will then run the tests and display the results in the console window.
Test suites contain one or more tests, as well as optional setUp and teardown functions, and a mocks table to define global functions and variables that should be mocked during the tests.

Example

The following is a simple test suite example:

local SampleSuite = {
	mocks = {
		UnitName = function(arg)
			return "Soandso";
		end;
	};
	setUp = function()
		return {};
	end;
	tearDown = function()
		-- no tear down required
	end;
	testExample = function()
		assert(UnitName("player") == "Soandso", "Expected player name to be 'Soandso'");
	end;
	testFailure = function()
		assert(UnitName("player") == "Feithar", "Expected player name to be 'Feithar'");
	end;
}

The mocks table defines any global functions that will be mocked. In this case, we want the API function UnitName to return the name "Soandso" when we're running our test, regardless of what argument is passed into the function. Mocked functions will be reset back to whatever they were originally defined as after each test is run.
The setup function should return a table that will be passed as an argument into all the test cases defined in the suite. Any setup that needs to be done should be placed here, and will be executed prior to running each test in the suite. The teardown function will likewise be run after each test in the suite.
The mock, setup, and teardown entries in the test suite are optional, and do not need to be defined if they are not needed.
Any function defined in the suite that has a name that starts with 'test' will be considered a test that should be executed as part of the suite. In this case, we have two tests, testExample and testFailure. testExample checks to see if the player's name is "Soandso". Since we defined a mock function above to replace the standard WoW API UnitName function, this test should pass, even if our character name isn't "Soandso". testFailure should fail, even if the developer logged into WoW as Feither, since the mocked UnitName function will report that the player's name is really "Soandso".
One the test suite is defined, it needs to be registered with WoWUnit with the following line of code:

WoWUnit:AddTestSuite("WoWUnitExample", WoWUnitTests);

This registers the suite and names it "WoWUnitExample". Now, the suite can be run in game by typing the following in a chat window:

/wowunit WoWUnitExample

WoWUnit will then run the tests, and display the output in the main chat window:

WoWUnit: Running 2 tests from suite WoWUnitExample...
WoWUnit: FAILED: WoWUnitExample:testFailure
WoWUnit: Interface\Addons\WoWUnit\WoWUnitTests.lua:23: Expected player name to be 'Feithar'
WoWUnit: Passed 1 of 2 tests.

Comments

Add a comment