Skip to content

Commit

Permalink
Removed broken link to example for running tests over multiple cycles…
Browse files Browse the repository at this point in the history
… and replaced with an example in the documentation/FAQ instead.
  • Loading branch information
sagatowski committed Feb 22, 2024
1 parent d42c7ba commit 8f0ecba
Showing 1 changed file with 25 additions and 4 deletions.
29 changes: 25 additions & 4 deletions docs/faq.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,31 @@ If you don’t find what you are looking for here, you can look through the:

## 1. How can I run a test across multiple PLC cycles?

This can be accomplished by keeping the function block under test as an instance variable of the test suite rather than the test method.
You can download an [example here](https://tcunit.org/temp/TimedTest_1x.zip).
In this example, the `FB_ToBeTested` is instantiated under the test suite (`FB_ToBeTested_Test`), and can thus be controlled over multiple cycles.
Then all that’s necessary to do is to set the condition for when the assertion should be made in the test itself, which in the example is when the `TestSuiteTimer` has elapsed (`TestSuiteTimer.Q`).
This can be accomplished by keeping the function block under test as an instance variable of the test method, using `VAR_INST`.
For example:

```example
METHOD PRIVATE MyTest
VAR_INST
fbTestTimer : TON := (PT := T#5S);
fbToBeTested : FB_ToBeTested;
END_VAR
-------
TEST('MyTest')
fbTestTimer(IN := TRUE);
// Do stuff here with fbToBeTested
IF fbTestTimer.Q THEN
// Make your assertions here or part of the test execution as a state machine
TEST_FINISHED();
END_IF
```

In this example, the `FB_ToBeTested` is instantiated under the test suite as an instance variable in the test-method, and can thus be controlled over multiple cycles.
Then all that's necessary to do is to set the condition for when the assertion should be made in the test itself, which in the example is when the `fbTestTimer` has elapsed (`fbTestTimer.Q`).
Note that you don't have to use a timer, this is just an example.
You can for example also use a state-machine that steps over various tests over multiple cycles instead.

**Required TcUnit version:** 1.0 or later

Expand Down

0 comments on commit 8f0ecba

Please sign in to comment.