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

Optimization of 'spec' attribute initialization in RESTestLoader class #261

Closed
migromarj opened this issue Nov 3, 2023 · 2 comments
Closed

Comments

@migromarj
Copy link
Contributor

Problem description

Currently, in the RESTestLoader class, the spec attribute is initialized in the createGenerator method. This means that, for example, when generating a report with Allure, on tests that have already been generated and executed, it is necessary to create a generator. This is because the createAllureReportManager method uses the spec attribute to find authentication property names (if any).

In a nutshell, what would be expected when generating a report with Allure would be:

RESTestLoader loader = new RESTestLoader(PROPERTY_FILE_PATH);

AllureReportManager allureReportManager = loader.createAllureReportManager();
allureReportManager.generateReport();

However, to generate a report with Allure we must do it in the following way:

RESTestLoader loader = new RESTestLoader(PROPERTY_FILE_PATH);

loader.createGenerator();

AllureReportManager allureReportManager = loader.createAllureReportManager();
allureReportManager.generateReport();

Proposed change

It is proposed to modify the initialization of the spec variable so that it is done in the readProperties method instead of createGenerator. This would improve decoupling, allowing all attributes to be defined once the property file is read, rather than having some, as in the case of spec, initialized in other methods.

Current code

You can see how the createGenerator method is in charge of initializing the spec attribute:

public AbstractTestCaseGenerator createGenerator() throws RESTestException {
    // Load specification
    spec = new OpenAPISpecification(OAISpecPath);

    ...
}

Proposed code

The initialization of the specification would be done only once by reading the properties of the file where they are contained:

private void readProperties() {
    ...

    OAISpecPath = readProperty("oas.path");
    logger.info("OAS path: {}", OAISpecPath);

    // Load specification
    spec = new OpenAPISpecification(OAISpecPath);

    ...
}

This could eliminate the operation of loading the specification in the createGenerator method:

public AbstractTestCaseGenerator createGenerator() throws RESTestException {

    ...

}
@mimbrero
Copy link
Member

+1, the only way to initialize #spec is by calling #createGenerator(), and in some cases it's not what you might want:

imagen

@josgarmar31
Copy link
Collaborator

Hello both,

Thank you very much for your contributions and suggestions. We have carefully reviewed the proposed changes and have incorporated them into the project in the latest commit. We appreciate your time and effort in improving the code and helping the project continue to grow.

If you have any other suggestions or find any further details that could be improved, please feel free to share them. Thanks again for your support!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants