[1.x only] An instance of the test class is created for every step #187
Comments
That is not by design. IIRC, a new instance should be created, at most, per
|
FYI, I'm using xbehave 1.1.0 and the ReSharper runner 1.6.2 |
I've done some investigation and it looks like you're correct, the xUnit.net runners are creating an instance of the class each time a step is executed. However, before that happens, xBehave.net creates an initial instance of the class and runs all the steps in the context of that initial instance. The other instances which are created by the xUnit.net runners are superfluous. I guess the reason that no-one has noticed this before is because, generally, the creation of an instance of the test class has no static side effects. I suppose in your case you have some static side effects which means the instances are interfering with one another. I've also confirmed that this behaviour does not occur in xBehave.net 2.0 (currently under development). xBehave.net 2.0 is based on xUnit.net 2.0, and both are complete re-writes. Is it possible for you to refactor your tests to remove the static side effects of multiple instances? Generally, if you can avoid using constructors and instead rely on |
Sorry, I just read back to your initial report and saw that you've done exactly what I've suggested and moved your common context from constructor to background. Is that a workable solution for you for the time being? Given that this bug has gone away in 2.0 I'd prefer not to spend time fixing it in 1.x if possible. 2.0 should go into beta before the end of the year and will have a stable release soon after xUnit.net 2.0 is stable. |
Thanks for looking into this. Using I liked the idea of using a constructor as I initially saw it more like cucumber's before hook. However as xbehave doesn't report the step in the test output it's not really a problem. |
Thanks very much for raising it and bringing it to my attention. It's good to know for future reference. |
Added to known issues for 1.x https://github.com/xbehave/xbehave.net/wiki/Known-Issues "A test class instance is created for each step" |
It seems that an instance of the test class is created for every step in the scenario. Is this by design? Is it avoidable in anyway?
I've moved the constructor code in to a Background method to minimize the impact of this.
The text was updated successfully, but these errors were encountered: