Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Proposal: TestScope helper #28

Open
1 task done
678098 opened this issue Sep 6, 2023 · 2 comments
Open
1 task done

Proposal: TestScope helper #28

678098 opened this issue Sep 6, 2023 · 2 comments
Labels
A-Testing Area: Testing enhancement New feature or request good first issue Good for newcomers

Comments

@678098
Copy link
Collaborator

678098 commented Sep 6, 2023

Is there an existing proposal for this?

  • 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 678098 added the enhancement New feature or request label Sep 6, 2023
@678098
Copy link
Collaborator Author

678098 commented Sep 6, 2023

@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 678098 added good first issue Good for newcomers A-Testing Area: Testing labels Sep 6, 2023
@sgalichkin
Copy link
Collaborator

sgalichkin commented Sep 6, 2023

@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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-Testing Area: Testing enhancement New feature or request good first issue Good for newcomers
Projects
None yet
Development

No branches or pull requests

2 participants