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

Skip to content

Conversation

@sclevine
Copy link
Owner

@sclevine sclevine commented Sep 5, 2018

  • Adds "global" focusing
  • Adds "global" reporting
  • Make other Options global (e.g., test order)
  • Doesn't introduce any global state πŸ˜„
  • No breaking changes to the API

Note: this is an untested prototype


Usage:

suite := spec.New("my suite", myreporter)

var _ = suite("my object", func(t *testing.T, when spec.G, it spec.S) {
...
}, spec.Random())

var _ = suite("my other object", func(t *testing.T, when spec.G, it spec.S) {
...
}, spec.Parallel())

func TestObject(t *testing.T) {
  suite.Run(t)
}

Or better:

var suite spec.Suite

func init() {
  suite = spec.New("my suite", myreporter)
  suite("my object", testMyObject spec.Random())
  suite("my other object", testMyOtherObject, spec.Parallel())
}

func testMyObject(t *testing.T, when spec.G, it spec.S) {
...
}

func testMyOtherObject(t *testing.T, when spec.G, it spec.S) {
...
}

func TestObjects(t *testing.T) {
  suite.Run(t)
}

@sclevine
Copy link
Owner Author

sclevine commented Sep 5, 2018

@joefitzgerald

@sclevine sclevine changed the title Prototype: Suites Major feature: Suites Sep 9, 2018
@sclevine
Copy link
Owner Author

sclevine commented Sep 9, 2018

Ready to merge.

@sclevine
Copy link
Owner Author

Less sure about this after more consideration. The same thing could be achieved with a single spec.Run that calls top-level functions. A more useful model would let you share focus/reporting between multiple Test* methods. Maybe this would be better:

// file 1

var suite = spec.New("my suite", myreporter)

var runTestObject = suite("test object", testObject)
func TestObject(t *testing.T) { runTestObject(t) }

func testObject(t *testing.T, when spec.G, it spec.S) {
  ...
}

// file 2

var runTestOtherObject = suite("test other object",  testOtherObject)
func TestOtherObject(t *testing.T) { runTestOtherObject(t) }

func testOtherObject(t *testing.T, when spec.G, it spec.S) {
  ...
}

(Also could use init in each file: having multiple init methods in a single package actually works!)

By looking up the Test* name, maybe we could do:

// file 1

var suite spec.Suite
func init() {
  suite = spec.New("my suite", myreporter)
  suite("TestObject", testObject)
  suite("TestOtherObject", testOtherObject)
}

func TestObject(t *testing.T) { suite.Run(t) }
func testObject(t *testing.T, when spec.G, it spec.S) {
  ...
}

// file 2

func TestOtherObject(t *testing.T) { suite.Run(t) }
func testOtherObject(t *testing.T, when spec.G, it spec.S) {
  ...
}

Which could also look like:

// file 1

var suite = spec.New("my suite", myreporter)
func init() {
  suite("TestObject", testObject)
}

func TestObject(t *testing.T) { suite.Run(t) }
func testObject(t *testing.T, when spec.G, it spec.S) {
  ...
}

// file 2

func init() {
  suite("TestOtherObject", testOtherObject)
}

func TestOtherObject(t *testing.T) { suite.Run(t) }
func testOtherObject(t *testing.T, when spec.G, it spec.S) {
  ...
}

Or maybe:

// file 1

var suite = spec.New("my suite", myreporter)

func init() {
  suite("TestObject", func(t *testing.T, when spec.G, it spec.S) {
    ...
  })
}

func TestObject(t *testing.T) { suite.Run(t) }


// file 2

func init() {
  suite("TestOtherObject", func(t *testing.T, when spec.G, it spec.S) {
    ...
  })
}

func TestOtherObject(t *testing.T) { suite.Run(t) }

@sclevine sclevine merged commit 18074d5 into master Oct 26, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants