tcunit / TcUnit

An unit testing framework for Beckhoff's TwinCAT 3
Other
258 stars 72 forks source link

Duration not calculated for TEST_ORDERED() tests #228

Closed dfreiberger closed 1 month ago

dfreiberger commented 9 months ago

Describe the bug Tests defined used TEST_ORDERED() do not appear to calculate the duration correctly. image

A quick look into the code reveals that the Test StartedAt may not be set, as shown in this screenshot for SetFinishedAndDuration(). image

It looks like a simple fix to the TEST_ORDERED FC to add Test.SetStartedAtIfNotSet(Timestamp := F_GetCpuCounterAs64bit(GVL_TcUnit.GetCpuCounter)); is necessary. I will try to submit a PR as soon as I have time for this.

To Reproduce Run any set of tests that include TEST_ORDERED tests. For example TestCase1C will be calculated incorrectly while TestCase1D is correct.

IF TEST_ORDERED('TestCase1C') THEN
    AssertTrue(TRUE, 'Condition is not true');
    TEST_FINISHED();
END_IF

TEST('TestCase1D');
    AssertTrue(FALSE, 'Condition is not true');
    AssertTrue(TRUE, 'Condition is not true');
TEST_FINISHED();

Expected behavior The duration should be calculated for the overall length of time that the test takes.

Software versions 1.3.0.0

Run environment Hardware PLC

dfreiberger commented 9 months ago

Easy fix in https://github.com/tcunit/TcUnit/commit/8fdf2564b54d48e4d64c646f0682e12227cb9d52

I will look at adding unit tests tomorrow before creating PR.

sagatowski commented 9 months ago

@dfreiberger Thanks for this discovery. Looking forward to your PR. ❤

Are you using TcUnit-VsExtension for your nice integration of TcUnit into TwinCAT?

Also, something feels different about the colors and font of your IDE? What nice font is that?

dfreiberger commented 9 months ago

@sagatowski yes, I am using TcUnit-VsExtension + the adapter using the branch I am working on at TcUnit-VsTestAdapter that can parse out tests via the TMC file and regex parsing for TEST and TEST_ORDERED sections. The fonts and colors I think are just defaults in TwinCAT VS 2019 although maybe I adjusted something at one point. The font is Consolas. image image

dfreiberger commented 8 months ago

Fixed in PR #231

sagatowski commented 1 month ago

Fixed in https://github.com/tcunit/TcUnit/pull/231.