Skip to content

Repository files navigation

Runit

pronounced "R Unit"

A unit testing library for Roblox heavily inspired by xUnit from C#

Caution

Depends on rbxts-transformer-flamework!

Example

src/scripts/run-tests.server.ts

import{TestRunner}from"@rbxts/runit";import{ServerScriptService}from"@rbxts/services";consttestRunner=newTestRunner(ServerScriptService.WaitForChild("Tests"));testRunner.run();

src/tests/number-utility.spec.ts

Test files must end in .spec.ts.

import{Fact,Theory,InlineData,Assert}from"@rbxts/runit";functiontoNearestFiveOrTen(n: number): number{constnearestFive=round(n/5)*5;constlowerTen=floor(nearestFive/10)*10;constupperTen=lowerTen+10;if(abs(n-lowerTen)<=abs(n-nearestFive))returnlowerTen;elseif(abs(n-upperTen)<=abs(n-nearestFive))returnupperTen;returnnearestFive;}classNumberUtilityTest{// tests one case
@FactpubliceightBecomesTen(): void{Assert.equal(10,toNearestFiveOrTen(8));}// tests multiple cases
@Theory
@InlineData(8,10)
@InlineData(14,15)
@InlineData(18,20)
@InlineData(3,5)
@InlineData(2,0)publicroundsToNearestFiveOrTen(input: number,expected: number): void{Assert.equal(expected,toNearestFiveOrTen(input));}}export=NumberUtilityTest;

Setup/Teardown

Setup can be done via the constructor. Teardown is done using the destroy method, which is automatically called after all tests have completed.

classMyTest{privatereadonlyjunk=newJunk;publicdestroy(): void{this.junk.destroy();}}

About

A unit testing library for Roblox heavily inspired by xUnit from C#

Topics

Resources

Stars

4 stars

Watchers

1 watching

Forks

Used by

Contributors

Languages