Skip to content

Adjust test runner to teardown and capture logs after X frames. #64

@mathew-odwyer

Description

@mathew-odwyer

I have a situation where I'm trying to provide a unit test for an "async" operation. Take the following case:

function test_should_return_true_after_one_frame()
{
    call_later(1, time_source_units_frames, function()
    {
        assertTrue(true);
    });
}

When running the test the test runner doesn't have time to capture the logs or whether or not the test passed, even though the assertion will pass.

Proposed Solution

What I've done personally is this:

// TestRunner.gml
static run = function() {
		setUp();
		var _len = array_length(suites);
		var i = 0;
		repeat (_len) {
			onRunBegin();
			suites[i].run();
			onRunEnd();
			++i;
		}
		
		// Wait a couple frames to allow any call_later or alarms to be hit.
	    call_later(async_wait_frames, time_source_units_frames, method(self, function() {
	        var i = 0;
			var _len = array_length(suites);
			
	        repeat (_len) {
	            captureLogs(suites[i]);
	            ++i;
	        }

	        tearDown();
	    }));
	}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions