mardi 8 août 2017

Can I use the TableDrivenTests concept in C++?

I know that in Go it is commonly used what is called TableDrivenTests to implement test cases, for example:

func TestMyFunc(t *testing.T) {
    var tTable = []struct {
        input  []float64
        result float64
    }{
        {[]float64{1, 2, 3, 4, 5, 6, 7, 8, 9}, 102.896},
        {[]float64{1, 1, 1, 1, 1, 1, 1, 1, 1}, 576.0},
        {[]float64{9, 9, 9, 9, 9, 9, 9, 9, 9}, 0.0},
    }

    for _, pair := range tTable {
        result := MyFunc(pair.input)
        assert.Equal(t, pair.result, result)
    }
}

Given a table of test cases, the actual test simply iterates through all table entries and for each entry performs the necessary tests.

I really like this Go style for implementing tests. So I want to know, is it possible to use something similar to it in C++? If it is possible, can you show me an example?

Aucun commentaire:

Enregistrer un commentaire