copypastedeveloper / given

Given is a bdd library made with the intent of wrapping common testing frameworks easily.
10 stars 2 forks source link

ShouldContain* method's output #14

Open KarsonAlford opened 9 years ago

KarsonAlford commented 9 years ago

When the lists being compared are large the output when they do not match is difficult to read.

In some cases I filter out the duplicates before calling the ShouldContain* method. Should this be done by Given?

        List<string> expectedValues;
        List<string> resultValues;

        // Remove identical items improves error messages.
        foreach (string o in expectedValues.Clone())
        {
            if (resultValues.Remove(o))
            {
                expectedValues.Remove(o);
            }
        }

        then(() => { resultValues.ShouldContainOnly(expectedValues); });
copypastedeveloper commented 9 years ago

how would this work with types other than strings/ints? reference equality?

KarsonAlford commented 9 years ago

Equality tests start with reference equality and only use an override if the reference is not equal. List<>.Remove() above is performing equality tests.

Also, often expected objects are contrived using the same objects used as input. Most of the time equality tests will be matching on references.