Skip to content

Unicon Unit Test Framework #431

Open

Description

@IanTrudel

This is an early implementation of an Unicon Unit Test Framework. Your feedback would be invaluable. @cjeffery @StephenWampler @brucerennie @Jafaral

  • TestCase
    • Support setupClass(), teardownClass(), setup and teardown.
    • Assertions through assertEqual(expected, actual), assertNotEqual(unexpected, actual), assert { expression } and assertFail { expression }.
    • TestTestCase unit tests cover TestCase.
  • TestSuite
    • Add a valid TestCase to the test suite.
    • Run the test suite (all the TestCases added).
      • Integration to CI:
        • EXIT SUCCESS when all tests pass.
        • EXIT FAILURE when one or more tests fail.
    • Calculate time elapsed.
    • TestTestSuite unit tests cover TestSuite.
  • TestReporter
    • Add results to the test reporter.
    • Summary of the results.
    • TestTestReporter unit tests cover TestReporter.
  • Mock (very early version)
    • TestMock unit tests cover Mock.

The draft PR is located here: #432
unittest.icn
tests.icn

Activity

  1. Jafaral commented on Apr 19, 2024

    @Jafaral
    Member

    Can you open a draft PR with these for easy review and inline feedback?

  2. IanTrudel commented on Apr 19, 2024

    @IanTrudel
    ContributorAuthor

    Can you open a draft PR with these for easy review and inline feedback?

    What workflow do you suggest? Clone or fork and then submit a PR?

    Which directory should these files go? unittest.icn is the package and tests.icn is the unit tests testing unittest package.

  3. Jafaral commented on Apr 20, 2024

    @Jafaral
    Member

    We use Fork/PR workflow (here ).

    Who are you targeting with this package? The language developers? or the language users, writing their own applications in Unicon and using the package to write tests? If it is the former, then it should go under unicon/tests/, if it is the latter (or both), then it should go under uniccon/uni/lib. The test itself should go under under unicon/tests/lib or unicon/tests/unicon.

  4. IanTrudel commented on Apr 20, 2024

    @IanTrudel
    ContributorAuthor

    There you go, as you requested! #432

    I haven't programmed in Icon since Ralph Griswold passed away and only few weeks with Unicon. There are most certainly a few things I would like to improve upon. Bootstrapping is the highlight at the moment, since the unittest package is used to test the unittest package. Looking forward to your feedback.

  5. Jafaral commented on Apr 20, 2024

    @Jafaral
    Member

    Thank you @IanTrudel. We would love to grow the community and have more people contribute to Unicon.

  6. IanTrudel commented on Apr 27, 2024

    @IanTrudel
    ContributorAuthor

    There is a working version updated in the draft with a reasonable test coverage. There is still a bit of work to do but the question is this worthy of a PR?

    The output looks like the following. exit(ts.run()) ensures that if one or more test fail, the build will fail.

    TestTestSuite_testInitialState
    
    TestTestSuite_testAddTest
    
    TestTestSuite_testAddNonTest
    
    TestTestSuite_testRunTests
    === TEST SUMMARY ===
    passed: 0, failed: 0
    ran 0 tests in 0.000000s
    SimpleTest_testAssertEqual
    
    SimpleTest_testAssert
    
    === TEST SUMMARY ===
    passed: 2, failed: 0
    ran 2 tests in 0.000092s
    
    TestTestSuite_testRuntime
    SlowTest_testSlow
    
    === TEST SUMMARY ===
    passed: 1, failed: 0
    ran 1 tests in 2.001685s
    
    TestTestSuite_testRunFailureTests
    FailureTest_testFailAssertEqual
    Assertion failed: expected 0, but got 9
    Assertion failed: expected Unicon, but got Icon
    
    FailureTest_testFailAssertNotEqual
    Assertion failed: unexpected 0, but got 0
    Assertion failed: unexpected Unicon, but got Unicon
    
    FailureTest_testFailAssert
    Assertion failed.
    Assertion failed.
    Assertion failed.
    Assertion failed.
    
    === TEST SUMMARY ===
    passed: 0, failed: 3
    ran 3 tests in 0.000122s
    
    TestTestCase_testInitialState
    
    TestTestCase_testResetStatus
    
    TestTestCase_testAssertEqual
    
    TestTestCase_testAssertNotEqual
    
    TestTestCase_testAssert
    
    TestTestCase_testAssertFail
    
    TestMock_testInitialState
    
    TestMock_testExpect
    
    TestMock_testVerify
    
    TestMock_testInvoke
    
    TestTestReporter_testInitialState
    
    TestTestReporter_testResult
    
    TestTestReporter_testRuntime
    
    TestTestReporter_testSummary
    === TEST SUMMARY ===
    passed: 0, failed: 0
    ran 0 tests in 0.000000s
    === TEST SUMMARY ===
    passed: 1, failed: 0
    ran 1 tests in 0.000000s
    === TEST SUMMARY ===
    passed: 1, failed: 1
    ran 2 tests in 0.000000s
    
    === TEST SUMMARY ===
    passed: 20, failed: 0
    ran 20 tests in 2.002867s
    
  7. IanTrudel commented on Jun 8, 2024

    @IanTrudel
    ContributorAuthor

    Is it possible to dynamically create methods and fields for a class? It would be helpful for the mocking of objects. What I have done at the moment is working but it's not as convenient as it could be.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions