On first glance after reading your description it seems to me you are making your tests too "complex". But in no way I can really say anything about it really before seeing your code, so maybe you could post your testproject code for us to study. Some in depth hints and tips;
"I've found a way around to call asserts only once in case a specific condition happens." To me this seems a good and valid way to assert something since PLC Function Blocks are mostly state dependent. Testing state dependent code is therfore itself also state depending. The clou is not to assert before you are sure that the code is in the 'to be asserted state'. Therefore running asserts continuously in such situations is not recommended. usually such a test is comprised of a CASE statement which guide the FB to the proper test state and then an assert to verify it.
Be aware that all tests need to be written in such a way that your test can be run in any order all the time and are thus not inter dependable on each other.
usually this means some stages are present in each test: initialise the testee, bring testee in test state, assert, de-initialise test.
Hoping to see your code posted here and with kindest regards
Haico
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Hello Haico,
thanks for the help and sorry for posting in the FAQs instead of in the tickets, I overlooked that and there was no way to edit it.
I admit that I'm quite a newbie with Codesys even if I did already some projects, so maybe some issues are due to my misunderstandings, and indeed I'm not used to write test cases.
I can't send you the original code, but I was able to reproduce the first issue in a project based on your examples, attached (Access violations).
I've put multiple cases inside it - working and not working - just activate the ones you want to test at each run. I'm using Codesys 3.5.16.20 and simulating that on the soft PLC (Codesys Control Win x86).
I will try to prepare also sample code for the other issue: usage of TEST/TEST_FINISHED/TEST_FINISHED_NAME and asserts (I hope in short time).
Regarding my third issue (usage of one timed test case for each test suite), it seems to me that the answer is that it is possible to have multiple timed test cases for each test suite, given that the variables are not shared (I don't want the result of a test case to influence the results of the others, for example with shared units under tests).
First off, thank you for your interest in coUnit.
On first glance after reading your description it seems to me you are making your tests too "complex". But in no way I can really say anything about it really before seeing your code, so maybe you could post your testproject code for us to study. Some in depth hints and tips;
"I've found a way around to call asserts only once in case a specific condition happens." To me this seems a good and valid way to assert something since PLC Function Blocks are mostly state dependent. Testing state dependent code is therfore itself also state depending. The clou is not to assert before you are sure that the code is in the 'to be asserted state'. Therefore running asserts continuously in such situations is not recommended. usually such a test is comprised of a CASE statement which guide the FB to the proper test state and then an assert to verify it.
Be aware that all tests need to be written in such a way that your test can be run in any order all the time and are thus not inter dependable on each other.
usually this means some stages are present in each test: initialise the testee, bring testee in test state, assert, de-initialise test.
Hoping to see your code posted here and with kindest regards
Haico
Ticket moved from /prj/cfunit/questions/18/
Hello Haico,
thanks for the help and sorry for posting in the FAQs instead of in the tickets, I overlooked that and there was no way to edit it.
I admit that I'm quite a newbie with Codesys even if I did already some projects, so maybe some issues are due to my misunderstandings, and indeed I'm not used to write test cases.
I can't send you the original code, but I was able to reproduce the first issue in a project based on your examples, attached (Access violations).
I've put multiple cases inside it - working and not working - just activate the ones you want to test at each run. I'm using Codesys 3.5.16.20 and simulating that on the soft PLC (Codesys Control Win x86).
I will try to prepare also sample code for the other issue: usage of TEST/TEST_FINISHED/TEST_FINISHED_NAME and asserts (I hope in short time).
Regarding my third issue (usage of one timed test case for each test suite), it seems to me that the answer is that it is possible to have multiple timed test cases for each test suite, given that the variables are not shared (I don't want the result of a test case to influence the results of the others, for example with shared units under tests).
Thanks again for the help.
Hi Haico,
maybe I've found the issue, please correct me if I'm wrong.
See CODESYS Support/POU/GetCurTaskInfo.
Suggested change:
IECTaskGetCurrent needs a pointer to a valid RTS_IEC_RESULT, not RTS_IEC_HANDLE, and the instance of the pointer was not initialized.
I'll hope this helps.
I'll check this when releasing v1.2.0.0