Skip to content

More easily read description for a False condition test #803

Open
@sofurihafe

Description

@sofurihafe

Description

When a test method is generated for "False" branch of a condition, the generated description is not obvious.
More readable - from the first glance - description would help the user to understand the test.

Context

  1. Set useAssembleModelGenerator to false in UtValueTestChecker,
  2. Add the following code as an integration test (use the same approach as in ClassWithNullableFieldTest),
  3. Generate tests for the following code and check the generated test file.
class FirstClass {
    SecondClass secondClass;

    FirstClass(SecondClass second) {
        this.secondClass = second;
    }
}

class SecondClass {
    FirstClass firstClass;

    SecondClass(FirstClass first) {
        this.firstClass = first;
    }
}

public class ClassWithNullableField {
    public FirstClass returnFirstClassWithNullableField(int value) {
        if (value == 0) {
            return new FirstClass(new SecondClass(null));
        } else {
            FirstClass first = new FirstClass(null);

            first.secondClass = new SecondClass(first);

            return first;
        }
    }
}

Expected behavior

A better solution need to be found.
Probably: add the parameter value to the description, like value = -255

Actual behavior

There are two test methods: value == 0 : False and value == 0 : True in Java doc and DisplayName annotation, while -255 is passed to the tested method as a parameter in first case.

Visual proofs

The following test class is generated:

    /**
    <pre>
    Test executes conditions:
 *     {@code (value == 0): False }
 * returns from: {@code return first; }
 * </pre>
     */
    @Test
    @DisplayName("returnFirstClassWithNullableField: value == 0 : False -> return first")
    public void testReturnFirstClassWithNullableField_ValueNotEqualsZero() throws Exception  {
        <...>

        FirstClass actual = classWithNullableField.returnFirstClassWithNullableField(-255);

        <...>
    }
    
    /**
    <pre>
    Test executes conditions:
 *     {@code (value == 0): True }
 * returns from: {@code return new FirstClass(new SecondClass(null)); }
 * </pre>
     */
    @Test
    @DisplayName("returnFirstClassWithNullableField: value == 0 : True -> return new FirstClass(new SecondClass(null))")
    public void testReturnFirstClassWithNullableField_ValueEqualsZero() throws Exception  {
        <...>

        FirstClass actual = classWithNullableField.returnFirstClassWithNullableField(0);

        <...>
    }

Environment

This bug doesn't show up in plugin (runIde) environment.

Metadata

Metadata

Assignees

Labels

comp-summariesSomething related to the method names, code comments and display names generationctg-enhancementNew feature, improvement or change request

Type

No type

Projects

Status

Todo

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions