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

Run configuration extra step #212

Closed

Conversation

just-rares
Copy link

This pull request solves issue #173

Added a method in the GetRunConfigurationStep that checks the weights of the RunConfiguration and asserts whether they are valid with all the information available at the moment.

Changes:

  • Check if the weights add up to 1.0
  • Check if there is a non-zero weight at mutants but Pitest is disabled
  • Check if there is a non-zero weight at line coverage but Jacoco is disabled

If the configuration is invalid, the default one is set and an exception is thrown.

I tests the functionality of this method in the RunConfigurationTests file, where I used both unit tests to check the requirements of the method under test, some mocking to allow for disabling Pitest and Jacoco and one integration test with a library file with invalid weights to assert the error is indeed thrown and caught in the Result file.

Notes:

  • I have left the default checks in the GradeCalculator. Some of the checks could not be done, such as the one with the grades. If it should be removed, please do let me know.

Any suggestions are welcomed, I am not very confident about my implementation of this issue

@Arraying
Copy link
Contributor

Approved workflow run.

Copy link
Contributor

@mauricioaniche mauricioaniche left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hey, @just-rares! Thanks for your first MR!

I wrote somme comments! Would you mind adjusting the code based on them?

if(!isValidRunConfiguration(runConfiguration)) {
// load default configuration
ctx.setRunConfiguration(new DefaultRunConfiguration(allClassesButTestingAndConfigOnes(ctx.getNewClassNames())));
throw new RuntimeException("The run configuration has invalid weights. Please check the file.");
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's throw a new exception, maybe AndyConfigurationException. Andy should stop in case the configuration is invalid, so in this sense, there's no need to set a default configuration!

Somewhere up we should catch this exception and generate an error output to the user. The message should clearly indicate this isn't the student's problem but the teacher's problem.

* @param config The run configuration of the problem
* @return validity of the config weights represented as a boolean
*/
public static boolean isValidRunConfiguration(RunConfiguration config) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This method would look better inside the RunConfiguration class itself. Look at it: 99% of it is interacting with data from that class, this is a sign that this method should be there.

import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.jupiter.api.Assertions.assertTrue;

public class RunConfigurationTests extends IntegrationTestBase {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These are unit tests, and they will look nicer once the rule is inside the RunConfiguration and you can simply call a config.isValid() rather than making a static method call to somewhere else

import java.util.List;
import java.util.Map;

public class Configuration extends RunConfiguration {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we still need an integration test, with a wrong configuration, and then, we assert that the produced Result contains the error message. (See other integration tests in the integration folder)

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should be the wrong configuration for one of the tests. Maybe I am understanding it wrong?

Here is the code for the test:

    @Test
    void checkExceptionHandling() {
        Result result = run("NumberUtilsAddLibrary", "NumberUtilsAddAllTestsPass", "NumberUtilsAddConfigurationInvalid");
        assertThat(result.getGenericFailure().getExceptionMessage().toString().contains("The run configuration has invalid weights. Please check the file.")).isTrue();
    }

Found in the test suite

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah ok, I missed the checkExceptionHandling. So, I'd split the unit tests from this integration test. Don't put them on the same file, as this isn't how we have been doing :)

@mauricioaniche
Copy link
Contributor

I just noticed the GradeWeights class. It also does some validations there (doesn't allow the sum not to be 100%). Are you using it here?

@mauricioaniche
Copy link
Contributor

I'm closing this one for now. We can always re-open once you are back to it!

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

Successfully merging this pull request may close these issues.

4 participants