ASP.NET MVC Unit Test - asp.net-mvc

I'd like to try unit test in ASP.NET MVC framework. But I don't know which unit test framework I have to choose.
NUnit, xUnit.net, MbUnit. or the unit test framework included with Visual Studio, which one is better?

If you are interested in following BDD guidelines, I highly recommend xUnit.NET with Moq as the mocking framework. The two are some of the most forward looking and modern unit testing frameworks available these days, and combined they make both a powerful and flexible unit testing platform. xUnit.NET is extremely extensible as its Fact and Trait attributes can be extended with your own attributes, and the testing frameworks behavior can be changed to suit your needs.
A great example of this flexibility is the ObservationAttribute and supporting framework to allow BDD style testing with xunit.net, found here:
http://iridescence.no/post/Extending-xUnit-with-a-Custom-ObservationAttribute-for-BDD-Style-Testing.aspx
I use the above BDD-style testing to create Test-Class-Per-Unit style BDD tests for my ASP.NET MVC controllers (well, and everything else I unit test, too.)

ASP.Net MVC doesn't make any specific demands of a framework, any will work just fine. NUnit is the most widely used, and for that reason it is my default choice.
Once you get into unit testing, some of the other frameworks offer different advanced features that you may like to check out.
I don't know anyone using the MS unit testing framework.

I would recommend to start from xUnit if your have not used any testing framework before. It's hard to decide which framework is better but I think that xUnit is the "most modern" among NUnit, MbUnit and MSTest. Start learning xUnit from this article and then this

I am using MSTest :) so now you know one ;)
Seriously, I think that MSTest is a the best framework for the start with TDD.
It is liteweight and it is generating all that you need for the wrapup and the most important thing, it is integrated in the visual studio...so, why don't you start with mstest and later on you can switch to advanced frameworks with no problems.
So in short, I would recomend a MSTest.
cheers

Related

Do we need more of an automation analyst's time in BDD than we would need in a non-BDD project?

I am new to BDD and willing to follow BDD methodology for my test Automation projects. Do we need more of an automation analyst's time in BDD than we would need in a non-BDD project?
The term BDD means behaviour driven development. It means development (not testing) derives from behaviour and that behaviour would be the acceptance criteria.
You can use the same scripts (Gherkin syntax ) for test automation but you need other tools as well (like selenium, WebUI etc.) to do actual test automation (For developer automation they can use the same business logic they have written to invoke from BDD scripts). So if an automation tester uses BDD then only thing they can do there is to create automation test scripts (in Gherkin syntax) and generate skeleton of the behaviour then to integrate with automation test frameworks. BDD is not the replacement of testing frameworks like selenium, QTP etc. Effort wise there will not be much difference (If you know test automation already) if you use BDD (Gherkin syntax) for your automation. One or the other place you have to write test scripts. If it is BDD then that will be Gherkin syntax in a file.

How to do ASP.NET MVC Integration testing using selenium

I need to know is it possible to perform integration testing using selenium for ASP.NET MVC applications. If yes then What are the requirements and how to do it. Will it be an external application to test from UI or should I be using views. Really confused. Please guide
If you are planning to write the Selenium tests using C#, which I'd recommend over using any kind of test recorder, then this will be a separate project.
You will run this and it will test a deployed version of your application, ideally in a dedicated test environment. There is extensive documentation available.
Personally I and others prefer WatiN for testing web applications using C# written tests.
Selenium can be used for testing any web applications include ASP.NET MVC. In general, you add test project to solution and write tests in it. Selenium open browser and execute commands that is described in your test. You can write test in c# or can use recorder and save record as c# test.

Which unit testing frameworks have ASP.NET MVC extensions?

I normally use MSpec and the fantastic Machine.Specifications.Mvc extensions, with extensions as ShouldBeAView(), ShouldBeARedirect(), ShouldHaveModelOfType<T>().
But I'll be writing a project for a client and since BDD and MSpec are not everyone's cup of tea and they'll be updating the code in the future I wanted to look at alternatives.
Just to compile a list of which possible Unit Testing Framework candidates for a coming ASP.NET MVC (3) project, which frameworks/libraries expose similar unit testing extensions for MVC?
These extensions are easy to write, I know, but I want to avoid reinventing the wheel.
Try here:
http://mvccontrib.codeplex.com/wikipage?title=TestHelper

SpecFlow / BDD Examples

Just looking for some examples of BDD/SpecFlow - ideally a projectб so I can see how to use SpecFlow on big projects where multiple features my reference the same steps etc.
I've read a few blogs over the last few months, but haven't had a nice, juicy project of someone else's to mooch around through.
The official example set of SpecFlow can be found on github: http://github.com/techtalk/SpecFlow-Examples
The ASP.NET-MVC/BookShop sample is the one that you can have a look. It is not a very big project though. (If you a need VS2010 sample, switch to the VS2010 branch.)
Another great place to find examples are from the tests for the SpecFlow project itself.
In particular those used to test the Gherkin parsing: https://github.com/techtalk/SpecFlow/tree/master/Tests/TechTalk.SpecFlow.Specs/Features
Those tests show a lot of ways to write scenarios using syntax for mutliline parameters, table parameters, templates, and more.
Also check out Steve Sanderson's GuestbookDemo, which shows off how to use SpecFlow with WatiN in ASP.NET MVC.
Also, see Brandon Satrom's recent MSDN article on the topic: http://msdn.microsoft.com/en-us/magazine/gg490346.aspx
We have used SpecFlow to formulate scenarios on the CQRS Journey project. Check out the overview of how we did it and then take a look at the acceptance tests themselves in the code repo.
I know it is an answered question. Just in case some one needs a quick simple web test project skeleton. I have created a nuget package SeleniumNUnitSpecflow for quickly setting up Specflow with Nunit and Selenium.
PM> Install-Package SeleniumNUnitSpecflow
Details: Web page BDD test with selenium specflow nunit

Functional test software/framework that covers Asp.Net Web Apps?

I recently began to use the NexusLight, a functional test automation framework.
Are there more frameworks that does a similar job?
Related question: End-to-End application testing from a users standpoint
I haven't really looked into NexusLight but I think InCisif.net is supposed to provide a functional test framework as well. You could look into it.
I test asp.net web apps for years and the only tool I use is Watir.
VSTT 2010 should be a good bet if you are looking for functional test automation. Web Services Testing, UI testing, Biztalk testing and Data Driven Testing Support. Please look at VSTT - http://msdn.microsoft.com/en-us/library/ee338734(v=vs.90).aspx
You can also try VSTT - http://blogs.msdn.com/b/slumley/archive/2009/05/28/vsts-2010-feature-enhancements-for-web-test-playback-ui.aspx
Telerik Test Tools - http://www.telerik.com/automated-testing-tools.aspx
Visual Studio UI Test Extensibility–Scenarios & Guiding Principles - http://blogs.msdn.com/b/mathew_aniyan/archive/2011/03/28/visual-studio-ui-test-extensibility-scenarios-amp-guiding-principles.aspx
VSTS Web Test Step-by-Step Primer - http://blogs.msdn.com/b/jimmymay/archive/2009/02/23/vsts-web-test-step-by-step-primer-7-minute-video-by-microsoft-a-c-e-performance-engineer-chris-lundquist-with-copious-notes-screen-shots-from-your-humble-correspondent.aspx
Found this one too:
http://www.automatedqa.com/products/testcomplete/index.asp
Unfortunately it's not free.
Reading a list made by Scott Hanselman, I found these two tools:
WatiN, to automated the tests;
WatiN Test Recorder, to automate the test code generation.
From WatiN page:
[...]WatiN (pronounced as What-in) website. Inspired by Watir development of WatiN started in December 2005 to make a similar kind of Web Application Testing possible for the .Net languages.
And from WatiN Test Recorder:
The purpose of the application is to generate code compatible with the WatiN (Web Application Testing In .NET) project.
Have a look at Seleno. It uses Selenium under the bonnet but abstracts all browser automation into Page Objects, which lead to well structured and fluid C# based tests.
It is particularly well suited to ASP.NET MVC, as each Page Object can be strongly typed (using Generics) to an equivalent MVC ViewModel, leading to a consistent relationship between View, ViewModel and Page Object.
Check out some of the samples in the Seleno codebase to see this in action.

Resources