TestSuite description

Roblox doesn’t let me say “testez” on the website, even though that’s the unfortunate name for the roblox-endorsed testing suite, so I moved my model’s description here.

This is a description for this model: https://www.roblox.com/library/3165903874/TestSuite

If you are unfamiliar with unit testing, watch this tutorial first. It’s about JavaScript, but relevant nonetheless:

I made my own testing suite as a module because injection is dumb and makes linting unbearable (talking about this:)
image

TestSuite is a module for basic unit testing that can be done in-studio and run with the command line.
Running tests through the command line is simple:
require(path.to.TestSuite).run(ancestor)

If the “ancestor” argument is not provided, it will search throughout the entire game for any ModuleScripts with names ending in “_spec”

All modules ending with “_spec” will be counted as test modules, but are not enjected with environment variables for the sake of linting. For convenience, they can be placed directly under the modules you want to test. Here’s some boilerplate for creating a simple unit test:

local TestSuite = require(path.to.TestSuite)

local myModule = TestSuite.use(script.Parent)
local describe = TestSuite.getAPI()

describe("My Module", function(it)
  it("Performs a specific behavior as expected", function(assert)
    local result = myModule.someFunction()
    assert.equal("Some expected value", result)
  end)
end)

return nil

This code will run each test described with an “It” clause, and will verify that the output of someFunction() is as expected (in this case, the string “Some expected value”).

You can use this module to ensure that you don’t fix an issue only to accidentally bring it back later. Just call TestSuite.run(), and all _spec modules in the game will be hotloaded/ran. Be sure to use TestSuite.use(module) rather than require(module), or else your module contents will cache.

Right now, only a few asserts are supported. More to come in the future. Here is the source code for defining them all of the different asserts. assert.is.X is equivalent to assert.X:

-- Positive assertions and aliases
assert.is.equal = makeAssert(ASSERTS.equal)
assert.is.equals = assert.is.equal

assert.is.same = makeAssert(ASSERTS.same)
assert.is.deep_equal = assert.is.same
assert.is.deep_equals = assert.is.same

assert.is.truthy = makeAssert(ASSERTS.truthy)
assert.is.falsy = makeAssert(ASSERTS.falsy)

assert.is.has_errors = makeAssert(ASSERTS.errors, false, true)
assert.is.errors = assert.is.has_errors
assert.is.error = assert.is.has_errors

assert.is.contains = makeAssert(ASSERTS.contains)

assert.has = assert.is

-- Negative assertions and aliases
assert.is_not.equal = makeAssert(ASSERTS.equal, true)
assert.is_not.equals = assert.is_not.equal

assert.is_not.same = makeAssert(ASSERTS.same, true)
assert.is_not.deep_equal = assert.is_not.same
assert.is_not.deep_equals = assert.is_not.same

assert.is_not.truthy = makeAssert(ASSERTS.truthy, true)
assert.is_not.falsy = makeAssert(ASSERTS.falsy, true)

assert.has_no = { errors = makeAssert(ASSERTS.errors, true, true) }
assert.does_not = { have_errors = assert.has_no.errors }
assert.is_not.has_errors = assert.has_no.errors
assert.is_not.errors = assert.has_no.errors
assert.is_not.error = assert.has_no.errors

assert.is_not.contains = makeAssert(ASSERTS.contains, true)
4 Likes

This topic was automatically closed after 1 minute. New replies are no longer allowed.