blazingmq-sdk-java icon indicating copy to clipboard operation
blazingmq-sdk-java copied to clipboard

Proposal: TestScope helper

Open 678098 opened this issue 2 years ago • 2 comments

Is there an existing proposal for this?

  • [X] I have searched the existing proposals

Is your feature request related to a problem?

We have a lot of lines like this:

        logger.info("==============================================");
        logger.info("BEGIN Testing SessionIT queue flush down.");
        logger.info("==============================================");

We might want to standartize this to avoid errors.

Describe the solution you'd like

I propose to make a helper class for this, the usage should look like this:

class ComponentIT {

  public testStress() {

    TestScope scope = new TestScope(this, "testStress");
    // should log:
    // ==================================
    // #BEGIN_TEST ComponentIT testStress
    // ==================================

    scope.step("Open session");
    // should log:
    // #STEP 1. Open session

    scope.step("Close session");
    // should log:
    // #STEP 2. Close session

    scope.end();
    // should log:
    // ==========================================
    // #END_TEST ComponentIT testStress - 13.21 s
    // ==========================================

  }

}

Alternatives you considered

No response

678098 avatar Sep 06 '23 13:09 678098

@sgalichkin what do you think? By the way, I don't want to add another indentation level just everywhere with try-with-resources for TestScope. And there is no guaranteed destructor call in Java to help us to auto-close it in the end.

678098 avatar Sep 06 '23 13:09 678098

@678098 in the past I was thinking of one of the following option:

  1. In methods annotated with @Before and @After use TestName rule to print the name of executing test See the following links: https://junit.org/junit4/javadoc/latest/org/junit/Before.html https://junit.org/junit4/javadoc/latest/org/junit/After.html https://github.com/junit-team/junit4/wiki/Rules#testname-rule
  2. Implement a TestWatcher: https://junit.org/junit4/javadoc/4.12/org/junit/rules/TestWatcher.html

In both cases we do not need to use try-with-resources.

I like the second option because we may implement the class only once (in util namespace) and then just use a final object with @Rule annotation in all test files. Since junit creates test class object for each test, we may include calculating and printing of spent time for each test in TestWatcher as well.

On another hand, I like the idea of using TestScope (as a final object field) to print steps.

sgalichkin avatar Sep 06 '23 15:09 sgalichkin