Skip to content
/ runit Public

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

Notifications You must be signed in to change notification settings

R-unic/runit

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

32 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Runit

pronounced "R Unit"

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

Example

src/scripts/run-tests.server.ts

import { TestRunner } from "@rbxts/runit";
import { ServerScriptService } from "@rbxts/services";

const testRunner = new TestRunner(
  ServerScriptService.WaitForChild("Tests")
);

testRunner.run();

src/tests/number-utility-test.ts

import { Fact, Theory, InlineData, Assert } from "@rbxts/runit";

function toNearestFiveOrTen(n: number): number {
  const nearestFive = round(n / 5) * 5;
  const lowerTen = floor(nearestFive / 10) * 10;
  const upperTen = lowerTen + 10;

  if (abs(n - lowerTen) <= abs(n - nearestFive))
    return lowerTen;
  else if (abs(n - upperTen) <= abs(n - nearestFive))
    return upperTen;

  return nearestFive;
}

class NumberUtilityTest {
  // tests one case
  @Fact()
  public eightBecomesTen(): 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)
  public roundsToNearestFiveOrTen(input: number, expected: number): void {
    Assert.equal(expected, toNearestFiveOrTen(input));
  }
}

export = NumberUtilityTest;

About

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

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published