Geeks With Blogs

@ignu
  • ignu @jimmybosse @coreyhaines no, phone calls sound like crap compared to Skype or FaceTime on a decent connection. about 409 days ago
  • ignu @coreyhaines i'm really pissed they've been calling us fat all these years. about 417 days ago
  • ignu scope avalanche about 419 days ago
  • ignu @repler i would read a comic book about that pizza dog too. about 422 days ago
  • ignu @ADJOTERUS spoiler: i heard the movie ends with scarlet witch saying "no. more. pizza." about 422 days ago

News

Len Smith's Facebook profile


nIgnuSharp.NET //len smith is a software developer in ann arbor, mi

I’m currently using context/specification style tests. While I think frameworks like J.P.Boodhoo’s are beautiful, I prefer something that works with ReSharper, TD.NET and CI without extra hurdles. I also want something my team, with limited exposure to *Unit frameworks, can easily pick up.

I’d prefer not to have the ceremony and misleading terminology of “Test” attributes, but its a trade-off I’m willing to make to more easily to integrate with team members and third party tools.

I put my testing stack along with an example test/spec project on github under the project name Specish.

About my tests/specs:

  1. resharper_navigationI preface every test fixture with the name of the class I’m testing. This lets me type “PC” in the navigation window of ReSharper to get to a PatientController or any class that tests patient controller.
  2. Automocks allow me to change constructor signatures with no consequence, and let me only mock objects and methods necessary for setup or verification. I stole the base class for my tests from here.
  3. I usually only have one assert per test method.
  4. I use a modified version of SpecExtensions I saw Steve Harman use at Cleveland Day of .NET last year… so instead of Assert.IsTrue(true) I write the more readable true.ShouldBeTrue();
  5. Custom ReSharper live templates for test fixtures and methods speed things up considerably.

The result looks something like this:

    [TestFixture] 
public class PatientController_when_searching_for_patients_returns_one_result : base_automock_test
{
ViewResult result;
IList<Patient> patients = new List<Patient>();

public override void establish_context()
{
patients.Add(new Patient{Id = 2});

Mock<IPatientService>()
.Setup(ps => ps.Search(It.IsAny<string>(), It.IsAny<string>()))
.Returns(patients);
}

public override void because()
{
result = Create<PatientController>().List("Joey", "Smith");
}

[Test]
public void it_returns_just_one_patient()
{
(result.ViewData.Model as Patient).ShouldEqual(patients[0]);
}

[Test]
public void it_returns_the_detail_view()
{
result.ViewName.ShouldEqual("Details");
}
}

And it shows up in the test runner as

PatientController when searching for patients returns one result

* it returns just one patient

* it returns the detail view

 

The test runner results document exactly how my controller behaves in this context.

PatientController returns just one patient and a detail view because I call List() on a PatientController in the context (search the returns one result) set in establish_context.

kick it on DotNetKicks.com

Posted on Sunday, May 31, 2009 5:43 PM | Back to top


Comments on this post: Automocking and BDD style tests with NUnit

# re: Automocking and BDD style tests with NUnit
Requesting Gravatar...
Ever since I saw you use this in your DI and TDD talk at CODODN, I've wanted to start using this in practice. Thanks for bringing it to my attention once again. I needed the swift kick in the hindquarters. :)
Left by Matt Brewer on Jun 01, 2009 9:02 PM

# re: Automocking and BDD style tests with NUnit
Requesting Gravatar...
Interesting,

this seems to be a bit misleading!

Keep up the good work
Left by Web developers on Oct 08, 2009 10:26 AM

# re: Automocking and BDD style tests with NUnit
Requesting Gravatar...
It was good to read your post and I will be coming here frequently to read more of your post. Thank you very much for your post once more.
Left by SMO Dubai on Mar 09, 2010 4:16 AM

# re: Automocking and BDD style tests with NUnit
Requesting Gravatar...
Great write-up, I am a big believer in commenting on blogs to inform the blog writers know that they’ve added something worthwhile to the world wide web!
Left by online crafts store on Dec 13, 2010 10:40 PM

# re: Automocking and BDD style tests with NUnit
Requesting Gravatar...
Interesting,

this seems to be a bit misleading!

Keep up the good work
Left by Antivirus Gratis on Mar 25, 2011 12:47 PM

# re: Automocking and BDD style tests with NUnit
Requesting Gravatar...
ASP.NET provides several exciting security controls, but these need to be understood properly and used wisely.ASP.NET application only performs database lockups and does not update any data, you only need to grant read access to the tables.
Left by Recupero Dati on Mar 25, 2011 12:49 PM

# re: Automocking and BDD style tests with NUnit
Requesting Gravatar...
It was good to read your post and I will be coming here frequently to read more of your post.
Left by Guadagnare Online on Mar 25, 2011 12:50 PM

# re: Automocking and BDD style tests with NUnit
Requesting Gravatar...
Great write-up, I am a big believer in commenting on blogs to inform the blog writers
Left by Finanziamenti on Mar 25, 2011 12:51 PM

# re: Automocking and BDD style tests with NUnit
Requesting Gravatar...
Update posting. Your writing on different issues have attracted many visitor of your site. I am finding useful information there almost every week.
Left by Cinema training on Apr 02, 2011 1:06 AM

# re: Automocking and BDD style tests with NUnit
Requesting Gravatar...
excellent articles... will come back to check tihs blog more often!
Left by recupero dati on Apr 04, 2011 4:43 AM

Your comment:
 (will show your gravatar)
 


Copyright © Len Smith | Powered by: GeeksWithBlogs.net | Join free