tcunit / TcUnit

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

Feature/add awaiting assertion capability #179

Open Navid-Mashayekh opened 2 years ago

Navid-Mashayekh commented 2 years ago

As you know in PLC world it is very common that we have function blocks which react to some inputs after some delay. To be able to test these FBs usually we need to use another TON in the test suite, pass the reference of it to the test method and pend the assertions and finish to this timer. Most PLC programs are full of TONs and TOFs and doing this procedure for every test is quite time consuming! In this update a function called "AWAIT_ASSERTIONS( AwaitTime : TIME ) is added to be used before writing assertions in test methods.

HAHermsen commented 2 years ago

Hi,

Great PR, but have you considered using CASE OF constructs in these type of scenario's? If an FB is State or Timer dependant, I always use CASE OF in order to get the Testee in the right state before asserting it.

With Kind regards

Haico

Navid-Mashayekh commented 2 years ago

Hi,

Great PR, but have you considered using CASE OF constructs in these type of scenario's? If an FB is State or Timer dependant, I always use CASE OF in order to get the Testee in the right state before asserting it.

With Kind regards

Haico

Hey @HAHermsen

Could you please be more clear about using CASE OF, I did understand your scenario!

I added this feature to be able to halt for a desired time until my FB generates the correct output. Imagine the scenario where you have FB to control a reservoir and you generate an Alarm by a HH floater, but normally due to water ripples you may put a TON of 2 or 3 seconds before generating the alarm. so to test this FB now all you need to do is put AWAITING_ASSERTIONS ( T#4S ) before your assertions in test method.

sagatowski commented 2 years ago

I'll start reviewing this PR as soon as this PR is completed/merged. Once it's merged, you will most likely need to merge from trunk again as the changes in the PR #159 will most likely break your branch.