nus-cs2103-AY2122S2 / forum

13 stars 1 forks source link

Difference between different tests for EditCommandTest #222

Closed jbkim1999 closed 2 years ago

jbkim1999 commented 2 years ago

While looking at the tests under EditCommandTest, I noticed when testing the execute method, there are different 'aspects' that are being tested.

For example, the code block for execute_allFieldsSpecifiedUnfilteredList_success() is like

    @Test
    public void execute_allFieldsSpecifiedUnfilteredList_success() {
        Client editedClient = new ClientBuilder().build();
        EditClientDescriptor descriptor = new EditClientDescriptorBuilder(editedClient).build();
        EditCommand editCommand = new EditCommand(INDEX_FIRST_CLIENT, descriptor);

        String expectedMessage = String.format(EditCommand.MESSAGE_EDIT_CLIENT_SUCCESS, editedClient);

        Model expectedModel = new ModelManager(new AddressBook(model.getAddressBook()), new UserPrefs());
        expectedModel.setClient(model.getFilteredClientList().get(0), editedClient);

        assertCommandSuccess(editCommand, model, expectedMessage, expectedModel);
    }

and execute_someFieldsSpecifiedUnfilteredList_success() is like

    @Test
    public void execute_someFieldsSpecifiedUnfilteredList_success() {
        Index indexLastClient = Index.fromOneBased(model.getFilteredClientList().size());
        Client lastClient = model.getFilteredClientList().get(indexLastClient.getZeroBased());

        ClientBuilder clientInList = new ClientBuilder(lastClient);
        Client editedClient = clientInList.withName(VALID_NAME_BURGER).withPhone(VALID_PHONE_BURGER)
                .withTags(VALID_TAG_TECH).build();

        EditClientDescriptor descriptor = new EditClientDescriptorBuilder().withName(VALID_NAME_BURGER)
                .withPhone(VALID_PHONE_BURGER).withTags(VALID_TAG_TECH).build();
        EditCommand editCommand = new EditCommand(indexLastClient, descriptor);

        String expectedMessage = String.format(EditCommand.MESSAGE_EDIT_CLIENT_SUCCESS, editedClient);

        Model expectedModel = new ModelManager(new AddressBook(model.getAddressBook()), new UserPrefs());
        expectedModel.setClient(lastClient, editedClient);

        assertCommandSuccess(editCommand, model, expectedMessage, expectedModel);
    }

The problem is, however, I know that they are different tests, but I just can't figure out which different areas they tackle for each method. Like, what is the meaningful difference between these two tests? From the method name alone, I can't get the full picture of it...

AAlghrairy commented 2 years ago

From what I can tell, it seems execute_allFieldsSpecifiedUnfilteredList_success() checks if all fields in the client can be edited with one command (by using the fields of he default person in PersonBuilder to build a descriptor and using the Edit Command to modify all fields of the person at INDEX_FIRST_CLIENT with the fields of the default person.

execute_someFieldsSpecifiedUnfilteredList_success() seems to only edit the name, phone number, and tags of one of the persons (builds an empty descriptor and sets only the fields for name, phone, and tags).

In other words, execute_allFieldsSpecifiedUnfilteredList_success() checks if all fields can be edited with one command, while execute_someFieldsSpecifiedUnfilteredList_success() checks if some fields can be edited while ensuring the rest of the unedited fields remain the same and do not have any unexpected modifications.

damithc commented 2 years ago

I believe @AAlghrairy is correct. @jbkim1999 the middle part of the test name is supposed to describe the test scenario. So, comparing the names of the two test methods is a good way to get started on figuring out the difference between the two.

jbkim1999 commented 2 years ago

I see, I thought the allFieldsSpecified was referring to the model itself (when getting the filtered ClientList), but didn't know it was meant for the EditCommand itself!

Thank you @AAlghrairy and @damithc for your kind advices. I shall close this issue now.