Skip to content

CommandLineParser tests should only test one feature per test case #150

@cmnbroad

Description

@cmnbroad

There are a lot of tests that are ganged up to test multiple features per case, but this can result in confusing and misleading results due to serial mutations of the test data. For example, the testNullOptionals method has code that purports to test that a required arg can't be set to NULL:

    //verify that required arg can't be set to null
    args[2] = "TRUTHINESS=null";
    final LegacyCommandLineArgumentParser clp2 = new LegacyCommandLineArgumentParser(fownl);
    Assert.assertFalse(clp2.parseArguments(System.err, args));

This test passes because the call to parseArguments does return false, but the false value results not from the attempt to set TRUTHINESS to null, but from the fact that an earlier call in the method to parseArguments sets the value of FROBNICATION_THRESHOLD to null (previous value 20). Because FROBNICATION_THRESHOLD has an initial value, the first parseArguments call treats it as optional. But once the state of FROBNICATION_THRESHOLD is set to null, the parser subsequently views it as required, and the next call returns false because of the attempt to set it to null. So the TRUTHINESS part of the test is never even triggered.

All of the tests should be separated to ensure the starting state is consistent.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions