Parameterized tests

123 views
Skip to first unread message

Jorge Gamba

unread,
Jul 16, 2010, 8:39:07 AM7/16/10
to machine_users
Hello, are there any plans to support parameterized specs?

Jorge Gamba

unread,
Jul 16, 2010, 10:29:15 AM7/16/10
to machin...@googlegroups.com
Tkank you very much for your response...

I'd like to know the reason why you don't plan support that feature implementation, just out of curiosity :).

Correspondingly, would you get a pull request about this feature implementation?

2010/7/16 Alexander Groß <agr...@therightstuff.de>
| Hello, are there any plans to support parameterized specs?

If you're referring to TypeFixtures (MbUnit) or RowTests, no, there are no
plans to support that.

What you can do is to "parameterize" observations by implementing a
[Behaviors] class containing "It"s and reference those from several
contexts:

[Behaviors]
public class FooBehaviors
{
  It should_do_xyz;
}

public class When_something_happens
{
  Behaves_like<FooBehaviors> a_something;
}

Fields from the context are copied to the class containing behaviors if they
are "protected static". Please refer to the
Machine.Specifications.Example.WithBehavior sample in the MSpec source tree.
Ironically, I was the one to implement this feature a while ago and find
myself using it very rarely, as in once in a fairly large project. The
downside of behaviors are that you pull context-specific information out of
the context class and have to navigate a lot more than if it were local.

If you want to parameterize (complex) setup of your SUTs you can borrow the
"With<T>" technique from [1]. Basically, it allows you to configure your SUT
by implementing a class that sets up one aspect of the SUT, like so

Establish = () =>
{
 var sut = new Sut();
 sut.With<SomeStateOrBehaviorThatCanBeReused>();
}

class SomeStateOrBehaviorThatCanBeReused : IBehaviorConfiguration
{
 public void Apply(object instance)
 {
   ((Sut) instance).SomeProperty = 42;
 }
}

There is no support for this in MSpec out of the box, but it should be
fairly simple to implement. The same disclaimer about locality applies here
as well.

Alex

[1] http://github.com/BjRo/xunitbddextensions
--
Alexander Groß
http://therightstuff.de/




--
Blog: http://gambasoft.net
Twitter: http://twitter/jorgegamba

Alexander Groß

unread,
Jul 16, 2010, 10:45:15 AM7/16/10
to machin...@googlegroups.com

With<T> is not implemented because I only learned about it a couple of weeks ago. :) Of course we do accept patches!

 

Alex

 

--

Alexander Groß

http://therightstuff.de/

 

--
You received this message because you are subscribed to the Google Groups "machine_users" group.
To post to this group, send email to machin...@googlegroups.com.
To unsubscribe from this group, send email to machine_user...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/machine_users?hl=en.

Jorge Gamba

unread,
Jul 16, 2010, 11:00:05 AM7/16/10
to machin...@googlegroups.com
Great! I confess that I've been working on that feature, inspired by Structuremap's With<>().

2010/7/16 Alexander Groß <agr...@therightstuff.de>

Aaron Jensen

unread,
Jul 16, 2010, 11:03:36 AM7/16/10
to machin...@googlegroups.com
Parameterized tests don't really fall within the realm of MSpec. MSpec
encourages you to name situations, to think about the English
description of the parts involved in a behavior. Parameterized tests
completely destroy this.

Parrameterized testing has it's place, but I believe it should be
relegated to other frameworks that are a bit looser on their guidance
as they are more multi purpose.

There's no reason one cannot have tests in multiple frameworks. I'd
encourage you to first consider why you want parameterized tests. Is
it because you just don't want to describe the scenarios you're
testing or is it because there is no value to do so? If it's the
latter you should consider using NUnit or one of the other frameworks
that support those kinds of tests for those situations.

Hope that helps,

Aaron

On Friday, July 16, 2010, Alexander Groß <agr...@therightstuff.de> wrote:
>
> With<T> is not implemented because I only learned about it a couple of weeks ago. :) Of course we do accept patches! Alex --Alexander Großhttp://therightstuff.de/ From: machin...@googlegroups.com [mailto:machin...@googlegroups.com] On Behalf Of Jorge Gamba


> Sent: Friday, July 16, 2010 4:29 PM
> To: machin...@googlegroups.com

> Subject: Re: Parameterized tests Tkank you very much for your response... I'd like to know the reason why you don't plan support that feature implementation, just out of curiosity :). Correspondingly, would you get a pull request about this feature implementation? 2010/7/16 Alexander Groß <agr...@therightstuff.de>| Hello, are there any plans to support parameterized specs?If you're referring to TypeFixtures (MbUnit) or RowTests, no, there are no

Alexander Groß

unread,
Jul 16, 2010, 11:11:23 AM7/16/10
to machin...@googlegroups.com
Aaron,

While I agree with you about parameterized tests, I think With<> still
can provide value for cases where the arrange is more complex and/or
repeated. Like behaviors, it's not the 80% solution but rather a tool
to use in specific cases, for example when you have a lot of scenarios
that share common setup.

Again, implementing With<> should be fairly simple so it does not
necessarily have to be part of the core framework.

Alex


--
Alexander Groß
http://therightstuff.de/

2010/7/16 Aaron Jensen <aaron...@gmail.com>:

Reply all
Reply to author
Forward
0 new messages