Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

xUnit v2 IUseFixture<> replacement

I'm trying to upgrade to xUnit 2 beta (mostly because of better test discovery) but stumbled over IUseFixture<>:

public abstract class TestCaseBase : IUseFixture<SelfHostFixture> 
{ /*common stuff here*/ }

public class Controller1Test : TestCaseBase {}

public class Controller2Test : TestCaseBase {}

I found that new IClassFixture<> was almost what I needed except the fixture was created/disposed for every descendant classes (Controller1Test, Controller2Test) instead of just once. Well, I could move IClassFixture<SelfHostFixture> declaration to every test class from the base but why would I setup/dispose my server multiple times? ICollectionFixture<> didn't worked for me (the fixture's ctor was never fired).

Basically, what I want is:

  1. "Per run" fixture (must be instantiated only once per tests run)
  2. Enable parallel runs because my tests are just stateless HTTP calls (I think ICollectionFixture<> won't work at all because tests within same collection cannot be run in parallel, right?)

What am I missing?

like image 718
UserControl Avatar asked Jan 05 '15 13:01

UserControl


1 Answers

Answer: use ICollectionFixture

See http://xunit.github.io/docs/shared-context.html

like image 121
Tim Lovell-Smith Avatar answered Sep 17 '22 15:09

Tim Lovell-Smith