Thanks to visit codestin.com
Credit goes to github.com

Skip to content

DSL for nested tests #13

@fogfish

Description

@fogfish

Let's consider the following test

func TestXXX(t *testing.T) {
   t.Run("foo", func(t *testing.T) { /* ... */ })
   t.Run("bar", func(t *testing.T) { /* ... */ })
   ...
}

It would be useful to has DSL for

func TestXXX(t *testing.T) {
   t.Run("foo", it.Then(t).Should(/* ... */))
   t.Run("bar", it.Then(t).Should(/* ... */))  
   ...
}

or even

func TestXXX(t *testing.T) {
   it.Ok("foo", t).Should(/* ... */))
   it.Ok("bar", t).Should(/* ... */))
   ...
}

Given syntax simplifies definition of table tests. Full example

func TestXXX(t *testing.T) {

Seq := func(t *testing.T, /* input for test */) it.SeqOf[SomeType] { /* ... common testing function ... */ }

 it.Ok("foo", t).Should(
    Seq(t, /*... */).Equal(/* ... expected results */)
 )

 it.Ok("bar", t).Should(
    Seq(t, /*... */).Equal(/* ... expected results */)
 )
}

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions