Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

XUnit test parallel execution #254

Closed
smyrman opened this issue Dec 14, 2017 · 12 comments
Closed

XUnit test parallel execution #254

smyrman opened this issue Dec 14, 2017 · 12 comments

Comments

@smyrman
Copy link

smyrman commented Dec 14, 2017

To quote the documentation:

Gomega uses a global (singleton) fail handler. This has the benefit that you don’t need to pass the fail handler down to each test, but does mean that you cannot run your XUnit style tests in parallel with Gomega. If you find this odious, open an issue on Github and let me know.

Gomega appears to be a pretty decent matcher library, but it would be nice to get better parallel execution support when using XUnit tests, e.g. allowing the initialization of a handler instance:

 m := gomega.NewTHandler(t)
 m.Expect(something).To(gomega.BeNil())
@rosenhouse
Copy link

rosenhouse commented Dec 27, 2017

Yes please. I would really like to use Gomega in a project that has XUnit-style tests, but I'm hesitant to introduce it, since it cannot be used in parallel tests.

@onsi
Copy link
Owner

onsi commented Dec 27, 2017

I just pushed a change to master that fixes this and updated the docs. Assuming a . import you can now:

g := NewGomegaWithT(t)
g.Expect(foo).To(BeNil())
g.Eventually(foo).Should(Equal("bar"))
g.Consistently(foo).Should(Equal("bar"))

@rosenhouse
Copy link

This works great, thank you!

@onsi
Copy link
Owner

onsi commented Dec 27, 2017

Great thanks! @smyrman wdyt?

@rosenhouse
Copy link

Just remember to (re-) initialize your g inside any subtests, e.g.

func TestConfigLoadMissingRequiredFields(t *testing.T) {
	requiredFieldNames := []string{
		"ServerCACertPath",
		"ClientCertPath",
		"ClientKeyPath",
		"Address",
		"PollInterval",
	}
	for _, n := range requiredFieldNames {
		fieldName := n // don't close over the iterator
		t.Run("required field "+fieldName, func(t *testing.T) {
			g := gomega.NewGomegaWithT(t)
...

@smyrman
Copy link
Author

smyrman commented Dec 29, 2017

@onsi, this looks like the right interface to me - looking forward to test it after the holidays 👍

@rosenhouse
Copy link

@onsi any chance you could cut a release with this commit? the downstream project I'm contributing to prefers that their dependencies be referenced by tag name. thanks!

@williammartin
Copy link
Sponsor Collaborator

@onsi Please loop me in if you do ^

Also, I couldn't find the documentation referenced in the issue, just want to make sure everything got updated as necessary.

@onsi
Copy link
Owner

onsi commented Jan 4, 2018

can do - but can't get to it till tonight at the earliest. I'll write up instructions for how to do it and commit them as well that way other committers can own this, too and we can iterate on it

@zachgersh
Copy link

hey @williammartin - I think it is probably safe to close this now?

@rosenhouse
Copy link

Yes, this issue is fixed.

@williammartin
Copy link
Sponsor Collaborator

Sweeeeet. Thanks all.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

5 participants