Lieven De Foor (TVH Parts Holding) asked a question.

ABLUnit - erratic behavior of test framework

I've noticed some unexpected/erratic behavior when creating unit tests:

 

  1. block-level on error undo, throw.
  2.  
  3. class ParentClass:
  4.  
  5. @BeforeEach.
  6. method public void BeforeEachParentTestPublic():
  7.  
  8. message "BeforeEachParentTestPublic"
  9. view-as alert-box info buttons ok.
  10.  
  11. end method.
  12.  
  13. @Test.
  14. method public void TestParent():
  15.  
  16. message "TestParent"
  17. view-as alert-box info buttons ok.
  18.  
  19. end method.
  20.  
  21. @AfterEach.
  22. method public void AfterEachParentTestPublic():
  23.  
  24. message "AfterEachParentTestPublic"
  25. view-as alert-box info buttons ok.
  26.  
  27. end method.
  28.  
  29. end class.
  1. block-level on error undo, throw.
  2.  
  3. class ChildClass
  4. inherits ParentClass:
  5.  
  6. // @BeforeEach.
  7. // method private void BeforeEachChildTestPrivate():
  8. //
  9. // message "BeforeEachChildTestPrivate"
  10. // view-as alert-box info buttons ok.
  11. //
  12. // end method.
  13.  
  14. @BeforeEach.
  15. method public void BeforeEachChildTestPublic():
  16.  
  17. message "BeforeEachChildTestPublic"
  18. view-as alert-box info buttons ok.
  19.  
  20. end method.
  21.  
  22. @Test.
  23. method public void TestChild():
  24.  
  25. message "TestChild"
  26. view-as alert-box info buttons ok.
  27.  
  28. end method.
  29.  
  30. // @AfterEach.
  31. // method private void AfterEachChildTestPrivate():
  32. //
  33. // message "AfterEachChildTestPrivate"
  34. // view-as alert-box info buttons ok.
  35. //
  36. // end method.
  37.  
  38. @AfterEach.
  39. method public void AfterEachChildTestPublic():
  40.  
  41. message "AfterEachChildTestPublic"
  42. view-as alert-box info buttons ok.
  43.  
  44. end method.
  45.  
  46. end class.
  • Annotated methods (@BeforeEach, @Test, @AfterEach) in the base class are not executed when running the tests on the derived class. I did not expect this, but could be by design. I'm not sure what the behavior is in other languages/unit test frameworks like NUnit or JUnut, but Gemini seems to indicate that there the base class' methods do get executed...
  • Erratic behavior when @BeforeEach method is private and NO public @BeforeEach method is present. In that case the BeforeEach is NOT executed, while the test method is executed twice!
  • When both a public and a private BeforeEach method exist, none is executed, but the test now runs once as expected.
  • When BeforeEach is public (and no private BeforeEach is present), things work as expected.
  • If there is a private AfterEach method, none of the AfterEach methods is executed.

 

Can anyone from @Progress provide some feedback on this behavior? Is there any documentation on the above (e.g. required access level of annotated methods, behavior when inheriting tests).


  • Peter Judge (Consultingwerk)

    > Annotated methods (@BeforeEach, @Test, @AfterEach) in the base class are not executed when running the tests on the derived class. I did not expect this, but could be by design. I'm not sure what the behavior is in other languages/unit test frameworks like NUnit or JUnut, but Gemini seems to indicate that there the base class' methods do get executed..

     

    To the best of my knowledge only the derived class' annotations are used. The xrefs from the parent classes are not read. The xrefs are used to determine which are the test and lifecycle (before/after) methods.

     

    I would hope that if and when strongly-typed annotations are added to the language that this issue would be resolved.

     

    All of the annotated methods must be public due to the fact that they are called via reflection/dynamic invocation. I'm not sure whether that's the case with other languages, but the the ABL can only call public members 'externally'.