Simple Unit Tests

version 1/130803 by Dannii Willis

  • Home page
  • Beginning
  • Previous



  • Example: * Basic Unit Tests - Passing and Failing

        "Basic Unit Tests"
        
        Include Simple Unit Tests by Dannii Willis.

        Test room is a room.
        
        Unit test (this is the passing rule):
            assert 5 is 5;
            assert 2 plus 2 is 4;
            assert {1, 2, 3} is {1, 2, 3};
            assert "happy" is "happy";
            say "hello!";
            assert the captured output is "hello!";
            assert the score is 0;
            assert the player is enclosed by the location;

        Unit test (this is the failing rule):
            assert {1, 2, 3} is {1, 2, 3, 4};
            assert "happy" is "sad";
            say "hello!";
            assert the captured output is "goodbye!";
            assert the player encloses a room;

        When play begins:
            try running the unit tests;