Rocha scripting library: unopinionated testing module


Unopinionated simple alternative to other testing solutions for roblox.
Inspired from the JavaScript library mocha

I wrote this really simple to use scripting library named Rocha. I made it because I found other testing solution such as TestEz, assert and Test Service either too hard or too simple to work with.

The module is made to be extended as it’s licensed to the WTFPL license. In other words, it is unopinionated.

The problem I had with the solutions I tried to use

They all had their own issue. As example, TestEz was too complicated to setup; I don’t want to use Rojo as I only want to build my game as simply as it can. As for assert and test service, both did not had enough function to compare value. Additionally, assert wasn’t having enough function to tell what test are being ran. In summary, all of the testing options I had tried did not had the feature that I want.

Relevant XKCD to sum up this paragraph:


rocha.isEqual<T>(value: T, expected: T)

Check if value is equal to expected
Return true if value is equal to expected

rocha.isNotEqual<T>(value: T, expected: T)

Check if value is not equal to expected
Return true if value is not equal to expected

rocha.doesNotThrow(func, ...)

Check if func does not throw any error
Return true if it doesn’t throw any error :sunglasses:

rocha.doesThrow(func, ...)

Check if func does throw any error
Return true if it does throw an error :sob:

rocha.describe(idx: number, desc: string)

Describe an test series(ie testing a specific feature set)
idx serve as a way to index the number count
desc serve as a describe for the testing feature set
Here is a example of what it could look like in use

Rocha.describe("only return false here :troll:"), "tro"), "lolo")
Rocha.describe("only return true. the true is for good people"), "😇") boolean, stepName: string)

Describe an test
condition: the test to check. if its false it result in a test failure
stepName: the name of the test, ie: use adding two number if its a test for an addition function


This example is about you using a functional class to check if the meta method works.

local rocah = require(script.rocah)
function createPosition(posX: number, posY: number)
  local class = { x = posX, y = posY }
  local metamethods = {
    __eq = function (t, value) 
      if t.x == value.x and t.y == value.y then
        return true
        return false
    __add = function (t, value)
      t.x += value.x
      t.y += value.y
      print(t.x, t.y, " - ", value.x, value.y)
      return t
   __tostring = function (t)
     return t.x .. ", " .. t.y
  local metatable = setmetatable(class, metamethods)
  return metatable 

rocha.describe(1, "Position class") -- I use 1 because it's the first test
local pos = gameLogicApi.createPosition(21, 0)
local pos2 = gameLogicApi.createPosition(21, 1) == pos2), "testing __equal metamethod"), 5) + gameLogicApi.createPosition(10, 15)) == rocha.createPosition(10, 20), 
  "__add metamethod"
), "21, 0")), "__tostring metamethod"))

I hope you liked this simple example made using a complex functional class lol :wink:

Gallery of the pleasure of using Rocha:


You can find Rocha on this GitHub gist


How likely is it that you want to recommend this library to a friend
  • Very Likely
  • Likely
  • Not sure
  • Unlikely
  • Very unlikely

0 voters

License bull!#?*

Copyright © 2021 ViniDalvino
This work is free. You can redistribute it and/or modify it under the terms of the Do What The Fuck You Want To Public License, Version 2, as published by Sam Hocevar. See for more details.

1 Like

Please keep your language professional, and avoid use of extreme profanity.

Regardless, this is pretty neat. This will save time/headaches for people not willing to dig too deeply.
I skimmed through the post, but when the functions do return false (when the script would supposedly error), does it mention what line it would error on, for ease of bug fixing?

1 Like

Sort of, it only show a message showing the traceback. Feel free to edit the code and to send an improved version.

It would not be constitutional to change as its a part of the script license and most importantly it is a part of the WTFPL. I am only considering to change it if a mod want me to.