cardiacsociety / web-services

MappCPD API and other services
0 stars 1 forks source link

Refactor tests #44

Open mikedonnici opened 6 years ago

mikedonnici commented 6 years ago

Use test groups rather than m.Run()

mikedonnici commented 6 years ago

At the moment have this:

func TestMain(m *testing.M) {
    err := data.SetupMySQL()
    if err != nil {
        log.Fatalln(err)
    }
    defer data.TearDownMySQL()

    err = data.SetupMongoDB()
    if err != nil {
        log.Fatalln(err)
    }
    defer data.TearDownMongoDB()

    m.Run()
}

Will change to this:

func TestMember(t *testing.T) {

    err := data.SetupMySQL()
    if err != nil {
        log.Fatalln(err)
    }
    defer data.TearDownMySQL()

    err = data.SetupMongoDB()
    if err != nil {
        log.Fatalln(err)
    }
    defer data.TearDownMongoDB()

    t.Run("member", func(t *testing.T) {
        t.Run("testPingDatabase", testPingDatabase)
        t.Run("testByID", testByID)
        // all test func with lowe case 'T'
    })
}