c# - How do I enforce test isolation in MSpec when static members/methods are required? -


ok. i'm trying wrap head around why mspec uses static methods / variables. (well not static methods, member variable delegates, it's practically same).

this makes impossible reuse contexts. or go through , make sure static variables reset manually. has no enforcement on test isolation. if 1 test sets variables , next 1 checks it, it'd pass when shouldn't.

this starting annoying. in 1 "because" statement should stay there, not carried through every other random test because it's sharing same context.

edit-

the question is, how "enforce" test isolation. example, @ specs below, sharing foocontext. let's take wild guess if should_not_throw passes?

public class foocontext {     establish context = () => subject = new foo();      public static foo subject;     public static int result;     public static exception ex; }  public class when_getting_an_int_incorrectly : foocontext {     because of = () => ex = exception.catch(() => result = subject.getint(null));       should_throw = () => ex.shouldnotbenull(); }  public class when_getting_an_int_correctly : foocontext {     because of = () => ex = exception.catch(() => result = subject.getint(0));      should_not_throw = () => ex.shouldbenull(); } 

it's technical , historic limitation.

  • you need statics fields share information between delegates (establish, because, it, cleanup).
  • mspec tries mimic rspec, think aaron considered delegates fit , released syntax see today in 2008 or 2009. syntax still in place today.

as context sharing / context base classes: state seems you're overusing concept. should initialize static fields in establish, global state become non-issue. context sharing should considered, so, quote you, doesn't happen randomly. try using helper methods complex setup , more verbose (i'd explicit) in establishs. make specs more readable.


Comments

Popular posts from this blog

scala - 'wrong top statement declaration' when using slick in IntelliJ -

c# - DevExpress.Wpf.Grid.InfiniteGridSizeException was unhandled -

PySide and Qt Properties: Connecting signals from Python to QML -