Aaron Jensen

Sponsors

The Lounge

Advertisement

Images in this post missing? We recently lost them in a site migration. We're working to restore these as you read this. Should you need an image in an emergency, please contact us at imagehelp@codebetter.com
MSpec v0.2

EDIT:Machine, including MSpec are now hosted on github: http://github.com/machine/machine

It's been a while, but we've gotten several new things into Machine.Specifications (MSpec). I'm excited to finally release them for everyone to start playing with. Don't know what MSpec is? Please, read my original post. You can grab the bits here.

Let's talk about what's new though. Here's an example of a new context/spec:

  [Concern("Console runner")]
  public class when_specifying_a_missing_assembly_on_the_command_line
  {
    Establish context = ()=>
    {
      console = new FakeConsole();
      program = new Program(console);
    };

    Because of = ()=>
      exitCode = program.Run(new string[] {missingAssemblyName});

    It should_output_an_error_message_with_the_name_of_the_missing_assembly = ()=>
      console.Lines.ShouldContain(string.Format(Resources.MissingAssemblyError, 
      missingAssemblyName));

    It should_return_the_Error_exit_code = ()=>
      exitCode.ShouldEqual(ExitCode.Error);

    const string missingAssemblyName = "Some.Missing.Assembly.dll";
    public static ExitCode exitCode;
    public static Program program;
    public static FakeConsole console;
  }

There have been a few semantic changes

  • The Description attribute has been removed. There is now an optional Concern attribute that allows you to specify a type and/or a string that the context/spec is concerned with.
  • Context before_each is now Establish context.
  • Context before_all is now Establish context_once.
  • Context after_each is now Cleanup after_each.
  • Context after_all is now Cleanup after_each.
  • When {...} is now Because of. This is closer to SpecUnit.NET's verbage, and doesn't force you to specify the "when" twice.

There is now a console runner

We don't quite have all the options we want yet, but the basics of the runner are working. Here's the help from the runner:

We also stole Bellware's SpecUnit.NET reporting stuff and ported it over. You can now generate a report on your specs with the --html switch. Here's an example run:

This is the report it generates.

Want to try it out?

  1. Grab the drop here.
  2. Extract it somewhere. Put it somewhere semi-permanent because the TestDriven.NET runner will need a static location for the MSpec TDNet Runner.
  3. If you want TestDriven.NET support, run InstallTDNetRunner.bat
  4. Check out the example in Machine.Specifications.Example. Note that you can run with TD.NET.
  5. Create a project of your own. Just add Machine.Specifications.dll and get started.
  6. Send me feedback! Leave comments, email me, tweet me, whatever.

Also, this is part of Machine, so feel free to take a look at the code and/or submit patches. There's also a Gallio adapter in there, but I didn't include it in the release as it's not quite polished enough yet. If you're interested in it, talk to me. Special thanks to Scott Bellware, Jeff Brown and Jamie Cansdale for their help and support. Also, extra special thanks to Eleutian's newest dev, Jeff Olson for much of the recent work that has gone into MSpec!


Posted Tue, Sep 2 2008 2:52 PM by aaronjensen

[Advertisement]

Comments

Scott wrote re: MSpec v0.2
on Tue, Sep 2 2008 6:01 PM

Looks awesome man, I'll grab it and run it through its paces this week!  I'm glad you guys  (you and Scott) put your heads together.  Thanks!

DotNetKicks.com wrote MSpec v0.2
on Tue, Sep 2 2008 7:02 PM

You've been kicked (a good thing) - Trackback from DotNetKicks.com

Reflective Perspective - Chris Alcock » The Morning Brew #171 wrote Reflective Perspective - Chris Alcock » The Morning Brew #171
on Wed, Sep 3 2008 3:04 AM

Pingback from  Reflective Perspective - Chris Alcock  » The Morning Brew #171

Joe Ocampo wrote re: MSpec v0.2
on Wed, Sep 3 2008 8:44 AM

This is really awesome.  I will have put it through it's paces.

Dew Drop - September 3, 2008 | Alvin Ashcraft's Morning Dew wrote Dew Drop - September 3, 2008 | Alvin Ashcraft's Morning Dew
on Wed, Sep 3 2008 9:08 AM

Pingback from  Dew Drop - September 3, 2008 | Alvin Ashcraft's Morning Dew

Bj??rn Rochel’s weblog » A new syntax for xUnit.BDDExtensions ??? wrote Bj??rn Rochel’s weblog » A new syntax for xUnit.BDDExtensions ???
on Thu, Nov 27 2008 8:22 AM

Pingback from  Bj??rn Rochel’s weblog » A new syntax for xUnit.BDDExtensions ???

Peter wrote re: MSpec v0.2
on Tue, Mar 17 2009 10:52 PM

I'm not sure if this was something I did or something I should have done. I should start by describing what I did at first, then describing how I enabled TD.NET integration:

1. Downloaded MSpec (specifically Machine.Specifications from the Machine page) from Github.

2. Opened Machine.Specifications.sln, F5 built it.

3. Oops, cleaned out Debug dir, switched to Release mode, F5 built it.

4. Copied entire source/distro/everything to %PROGRAMFILES%\mspec

5. Found Distribution\Specifications\ directory and ran InstallTDNetRunner.bat

... this is when I reported the problem. Step 6 (fixed the problem) is:

6. Copied Machine.Specifications.TDNetRunner.dll from Release\ folder to the Distribution\Specifications\ folder (this is where batch file/registry hack in #5 told TD.NET to look)

Anyway thanks for your attention, this is resolved.

#.think.in wrote #.think.in infoDose #31 (24th May - 1st June)
on Mon, Jun 1 2009 9:12 AM

#.think.in infoDose #31 (24th May - 1st June)

Tad wrote re: MSpec v0.2
on Sat, Sep 5 2009 1:08 PM

Hi,

I'm using MSpec right now but found very strange "bug", it doesn't make difference if I use Establish context  or Establish context_once becuse it is executed only once and for cleanup is the same , it it appropriate behavoiur ?

aaronjensen wrote re: MSpec v0.2
on Sat, Sep 5 2009 5:36 PM

Hi Tad,

The documentation in this post is a bit out of date. The context is executed once and only once regardless of what you name it. If you want it to execute before each specification you can add the SetupForEachSpecification attribute to your context, though I strongly advise against it. Specifications are meant to be observations. Observations do not mutate state. There is no reason to set up the context more than once if you're adhering to this guidance.

Tad wrote re: MSpec v0.2
on Sun, Sep 6 2009 5:58 AM

Hi,

Thanks for information :) I have  one more question, is it possible to have only one setupFixture which would execute only once for many tests (test classes)?  I would like to have one base class with context and execute that context only once and share it beetween test classes , but don't know if it possible

aaronjensen wrote re: MSpec v0.2
on Mon, Sep 7 2009 7:53 PM

If you only need to do it once (like set up something expensive) you can use an AssemblyContext. Just implement IAssemblyContext in a class in one of your spec assemblies and MSpec will invoke it. Hope that helps.

Arthur wrote re: MSpec v0.2
on Tue, Sep 22 2009 8:21 AM

Hi, just saw your update.

Why did you decide to introduce: Establish context, Cleanup, etc. ?

I would suggest:

Before each = () => {...}

Before all = () => {...}

same for: After each/all

Best regards,

Arthur

aaronjensen wrote re: MSpec v0.2
on Tue, Sep 22 2009 10:57 AM

In my experience, there is no real need for Before each. If you need Before each, you are doing something in your observations that is mutating state. That, by definition, is not an observation. I allow for this if you really need it by adding an attribute.

As for the actual wording, I (and others that I've discussed it with) feel that the current wording is more descriptive and intention revealing.

aaronjensen wrote re: MSpec v0.2
on Tue, Sep 22 2009 11:06 AM

Actually, this post isn't even the latest. I just realized you were talking about Establish context and context_once. The once nomenclature is gone for reasons I previously described.

Arthur wrote re: MSpec v0.2
on Tue, Sep 22 2009 11:15 AM

Before each is a kind of setup isn't it? Or do you create a new instance of test class before running each test?

So the question is: why we don't need before each?

Arthur wrote re: MSpec v0.2
on Tue, Sep 22 2009 12:06 PM

Actually, I'm preparing state in [before each], not mutating it.

Otherwise, where do you suggest to prepare the state?

aaronjensen wrote re: MSpec v0.2
on Tue, Sep 22 2009 12:41 PM

kodart,

Preparation is mutation. I was not talking about not mutating in the context though, I was talking about not mutating in the specifications (It).

I do not create a new context for each specification. Before each or Establish context as it's called now, is in fact a set up, but as I stated, it only needs to be set up once because the specifications should be read-only aka not mutate state.

Arthur wrote re: MSpec v0.2
on Wed, Sep 23 2009 9:26 AM

I got it!

Another suggestion is regarding Behaves_like that I saw in an article on EleganceCode (elegantcode.com/.../mspec-take-2)

We can see unnecessary repetition:

Behaves_like<NoSalesTaxAdded> no_sales_tax_added;

It is better to introduce and apply attribute:

[Behaves_like<NoSalesTaxAdded>]

Actually do the same for

[Concern(typeof(Account), "Funds transfer")]

=>

[Concern<Account>("Funds transfer")]

Regards Arthur

aaronjensen wrote re: MSpec v0.2
on Wed, Sep 23 2009 10:39 AM

Arthur,

Unfortunately, generics are not supported in attributes at the moment. Wish they were :)

Tom Janssens wrote re: MSpec v0.2
on Tue, Oct 20 2009 7:21 AM

Hey Aaron,

First of all : I really appreciate your work on MSpec; it conviced me to try out BDD for the first time in .Net/c#, and I must admit I like it a lot.

Just wanted to mention you that I have written a few articles over on my blog on how to get started with MSpec, together with asp.net mvc, FluentNhibernate, Castle Windsor and Git; you can find it here : www.corebvba.be/blog

Kind regards,

Tom

Paul wrote re: MSpec v0.2
on Fri, Nov 6 2009 3:35 PM

Love MSpec, but can't figure out how to get the built-in test runner to run it with debugging.  Any advice?

aaronjensen wrote re: MSpec v0.2
on Fri, Nov 6 2009 11:22 PM

Thanks! The best thing to do is to either use the R# runner or the TD.net runner and run with debugging. Otherwise, you can put a Debugger.Breakpoint() wherever you want to break in your code. *or* (I think) you can set your executable for your test assembly to be the mspec runner w/ appropriate commandline parameters, set it to the startup project, add some breakpoints and just hit f5. Hope that helps!

Aaron Jensen wrote MSpec v0.3
on Wed, Nov 18 2009 1:20 PM

It’s been more or less forever since I’ve incremented the version number of MSpec so I went ahead and

Add a Comment

(required)  
(optional)
(required)  
Remember Me?