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

UnitTests: Explicitily call $Self->DoneTesting() at the end of scripts #293

Closed
bschmalhofer opened this issue Aug 2, 2020 · 2 comments
Closed
Assignees
Labels
enhancement New feature or request
Milestone

Comments

@bschmalhofer
Copy link
Contributor

bschmalhofer commented Aug 2, 2020

I suspect that there are some cases where test scripts exit before they reach the end of the script. This should be flagged as problems when the test are run with prove.
These cases can be caught by explicitly calling $Self->DoneTesting() explicitily at the end of the script.

Currently DoneTesting() is called in an the END block provided by Kernel::System::UnitiTest::RegisterDriver . But this is not sufficient as DoneTesting() is also called when the script exits early.

Just to muddy the water, there are 104 scripts that already call DoneTesting() explicitly. This makes no sense whatsoever, as in these case the plan is printed twice.

Just to be on the safe side the method Kernel::System::UnitTest::Driver::DoneTesting() should print nothing when the test script is run via Dev::UnitTest::Run. This can checked by inspecting the call stack.

The check for PlanWasSubmitted() can be removed, as the test script author is responsible for calling either $Self->Plan() or $Self->DoneTesting().

This plan required that destructors do not execute test functions. The only apparent case is Kernel::System::UnitTest::DESTROY(). In this sub the test functions can be replaced by calls to Note().

@bschmalhofer bschmalhofer added the enhancement New feature or request label Aug 2, 2020
@bschmalhofer bschmalhofer added this to the OTOBO 10.1 milestone Aug 2, 2020
@bschmalhofer bschmalhofer self-assigned this Aug 2, 2020
@bschmalhofer
Copy link
Contributor Author

bschmalhofer commented Aug 3, 2020

TODO:

  • sanity check when run with 'prove*

  • sanity check when run with 'Dev::UnitTest::Run', this is compare with the result from a run with OTOBO 10.0.x

bschmalhofer added a commit that referenced this issue Aug 3, 2020
Looks like this was a temporary hack during development.
bschmalhofer added a commit that referenced this issue Aug 3, 2020
bschmalhofer added a commit that referenced this issue Aug 3, 2020
So that layer caching cab help to avoid some work.
bschmalhofer added a commit that referenced this issue Aug 3, 2020
Is sane because tests from DESTROY are gone now.
@bschmalhofer
Copy link
Contributor Author

Compared the output of two runs with Dev::UnitTest::Run. There are many diffs because things like dates and IDs are different. But altogether everything is looking good. Closing.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

1 participant