rafaeljusto/redigomock

Using gocheck testing framework

Closed this issue · 2 comments

Hi,
I was wondering if it would be ok to introduce dependency on gocheck testing framework http://labix.org/gocheck.

It is really nice improvement compared to go builtin test framework. And both of them can be used simultaneously in the same package.

I prefer to avoid the project dependencies. The built-in test framework already give us all the necessary tools to organize our tests. Maybe they could be written in a better way. In some big Go projects I usually use the following structure:

func TestNormaliseName(t *testing.T) {
    data := []struct {
        description string
        name string
        expectedResult string
    }{
        {
            description: "It should return the string intact",
            name: "Ataulfo",
            expectedResult: "Ataulfo",
        },
        {
            description: "It should capitalise the first letter",
            name: "ataulfo",
            expectedResult: "Ataulfo",
        },
        {
            description: "It should remove spaces and emoticons",
            name: "   Ataulfo  :-P",
            expectedResult: "Ataulfo",
        },
    }

    for i, item := range data {
        result := normaliseName(item.name)

        if result != item.expectedResult {
            t.Errorf(
                "Item %d, “%s”: mismatch results. Expecting '%s'; found '%s'",
                i,
                item.description,
                item.expectedResult,
                result,
            )
        }
    }
}

Following the minimalist design, less is more.

Best regards,
Rafael

Hi,

Sure, I will stick with builtin tests then :)

Regards,
Maciej