+ Reply to Thread
Results 1 to 2 of 2

Thread: unit testing using Nunit

  1. #1

    unit testing using Nunit

    I'm creating a unit testing with NUnit, I'm writing a simple test to get used to thesyntax and the way of unit testing. But I'm not sure if I'm doing it right with the following test:
    The class under test holds a list of strings containing fruit names, where new fruit names can be added via class_under_test.addNewFruit(...). So, to test the functionality of addNewFruit(...), I first use the method to add a new string to the list (e.g. "Pinapple") and, in the next step, verify if the list contains this new string.
    public void addNewFruit_validNewFruitName_ReturnsFalse()
        string newFruit = "Pineapple";
        bool result = class_under_test.isInFruitList(newFruit);
    Is this the way to test this function, or are there better solutions?
    Thanks in advance for any help.

  2. #2
    Junior Member
    Join Date
    Jan 2012
    every unit test can only be broken in single way. Every unit test "lives" in isolation to every other. Your addNewFruit test can be broken by breaking isInFruitsList

    Since you already tested isInFruitsList method, you don`t have to worry about that. That's like using 3rd party API - it is tested, and you assume it works. In your case, you assume isInFruitsList works because, well - you tested it.

    Going around the "broken in a single way" you could try to expose underlying fruits list internally (and use InternalsVisibleTo attribute), or passing it via dependency injection. Question is - is it worth the effort? What do you really gain? In such simple case, you usually gain very little and overhead of introducing such constructs usually is not worth the time.

+ Reply to Thread


Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts