Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Unicon Unit Test Framework #431

Open
18 tasks done
IanTrudel opened this issue Apr 19, 2024 · 7 comments
Open
18 tasks done

Unicon Unit Test Framework #431

IanTrudel opened this issue Apr 19, 2024 · 7 comments

Comments

@IanTrudel
Copy link

IanTrudel commented Apr 19, 2024

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

@Jafaral
Copy link
Member

Jafaral commented Apr 19, 2024

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

@IanTrudel
Copy link
Author

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.

@Jafaral
Copy link
Member

Jafaral commented Apr 20, 2024

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.

@IanTrudel
Copy link
Author

IanTrudel commented Apr 20, 2024

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.

@Jafaral
Copy link
Member

Jafaral commented Apr 20, 2024

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

@IanTrudel
Copy link
Author

IanTrudel commented Apr 27, 2024

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

@IanTrudel
Copy link
Author

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
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants