JanetRossini.github.io

Lua, LSL, Blender, Python in Second Life


Project maintained by JanetRossini

A Bit More CodeaUnit

Jul 12, 2025 • [designluatesting]


Let’s do a bit more with the CodeaUnit cloning. Maybe before / after?

I’ll write a test. And improve any code that I notice isn’t looking all that good. Thing one, I think I’ll change the magic word from “suite” to “feature”. Then a setup and tear down.

function _:featureST()
   local count = 0
   _:describe("Setup / Teardown", function()
      _:setup(function()
         count = 0
      end)
      _teardown(function()
         count = 0
      end)

      _:test("Count 3", function()
         _:expect(count).is(0)
         count += 3
         _:expect(count).is(3)
      end)

      _:test("Count 4", function()
         _:expect(count).is(0)
         count += 4
         _:expect(count).is(4)
      end)
   end)
end

I think that’ll do the trick. Now to implement …

I have good news and bad news. The good news is that my tests are all running. The bad news is that some of them are running twice:

Feature: Initial Test Suite
Actual: Bar, Expected: Foo.  Tests:
All Tests: Pass 1 Fail 1 Ignored 0.  Tests:Initial Test Suite
Feature: Setup / Teardown
All Tests: Pass 4 Fail 0 Ignored 0.  Tests:Setup / Teardown
Feature: Initial Test Suite
Actual: Bar, Expected: Foo.  Tests:Setup / Teardown
All Tests: Pass 1 Fail 1 Ignored 0.  Tests:Initial Test Suite

A bit of printing and I am sure that … ohhh, I know. I bet we’re adding things to the Tests table as we go, somehow. I bet if I copy the table, it’ll be OK. And it is. But what was adding to the object?

A few changes and everything is fine. I did go so far as to turn Tests from a table into a class. That may have been too far.

I’ll pause here but I have both the new scheme and the old one running.

Sunday Morning

Ag this writing, all my old tests pass, including the full 894 assertions of the bezier-related development file. And my new tests for the expect method pass. And my current tests for the full “suite” capability also pass. They look like this:

local Tests = require('./tests')
local _ = Tests

function _:featureTestSuite()
   _:describe("Initial Test Suite", function()

      _:test("Equality Test", function()
         _:expect("Foo").is("Foo")
      end)

      _:test("Expected to Fail", function()
         _:expect("Bar").is("Foo")
      end)
   end)
end

function _:featureST()
   local count = 0
   _:describe("Setup / Teardown", function()
      _:setup(function()
         count = 0
      end)
      _:teardown(function()
         count = 0
      end)

      _:test("Count 3", function()
         _:expect(count).is(0)
         count += 3
         _:expect(count).is(3)
      end)

      _:test("Count 4", function()
         _:expect(count).is(0)
         count += 4
         _:expect(count).is(4)
      end)
   end)
end

Tests:execute()

The result looks like this:

Feature: Setup / Teardown
Pass 4 Fail 0 Ignored 0.  Test: Setup / Teardown

Feature: Initial Test Suite
Actual: Bar, Expected: Foo.  Test: Expected to Fail
Pass 1 Fail 1 Ignored 0.  Test: Initial Test Suite

I’m not satisfied with that output. I would prefer not to echo the name of the suite on the summary line, and perhaps it should say “Summary”, etc.

But it is all working, even if we mix the new form and the old form.

The Plan?

We have the old Tests object safe in Git and on GitHub. I propose now to remove all the old stuff and refactor toward better code. Perhaps a better way to put it is that I plan to refactor toward better code, removing the old Tests:test_something form of tests along the way.

I think I’ll do that in a new article, which I’ll start right now.

Safe paths, see you there!