Optimization of 'spec' attribute initialization in RESTestLoader class
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 {
...
}
+1, the only way to initialize #spec is by calling #createGenerator(), and in some cases it's not what you might want:
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!