Mocks with Visual Studio 2010 Ultimate - c#

Should I keep using Mocks with Visual Studio 2010 Ultimate?, I mean, all the information I'm gathering about mocks is kinda old, from like 2 or 3 years ago, more specific, I'm gathering info about the next frameworks Rhino Mocks and Moq.
But then, I don't know if I'm looking for something old or deprecated or that it's not used nowdays... I'm making a new project and I want to used the last frameworks to implement the TDD in the best way possible, and since we recently acquired the Ultimate version of VS2010, which has a lot info and utilities about testing, I wanna do the things the way they should be done.
Oh, I almost forgot, I have to use VB, and most of the info about these frameworks are in C#, I don't know if that could be relevant...
Thanks in advice!
EDIT
Moq along with AutoFixture did the job

Moq is my mocking framework of choice, but that's just a personal preference. And it doesn't really matter that the samples are typically written in C#, provided you can read C#, since you can use all the same methods, but with a slightly different syntax.
You really can't go wrong with either Moq or RhinoMocks.

Rhino and Moq will both give you what you need. If money is not an issue I would also suggest Typemock.

Rhino, Moq and (my favorite) FakeItEasy are nice mocking/faking frameworks.
It shouldn't matter which language you're testing in (VB or C#), but to be safe check the docs for all these frameworks. I know FakeItEasy supports VB.NET. You should also look into Roy Osherove's book about unit testing in .NET, highly recommended.

I tend to look at the activity on the web site where the source is hosted and try to work out whether a project is being actively maintained. If there is good developer velocity then that's usually a sign of a well-supported project. All of the mocking frameworks mentioned here are fairly good bets, my personal favourite is Moq and I like to use it with MSpec (Machine.Specifications), but of course each developer or team needs to make those choices for themselves.
If you haven't already, get the NuGet plugin for Visual Studio and use that to install all your frameworks. If you are using a CI build and don't want to check these items into your version control, there is a 'no-commit workflow' for NuGet that uses the NuGetPowerTools package.
Regarding the examples being in C#, you can use the Telerik Code Converter to easily translate them into VB.

Related

How can I get code coverage info on code called by CSLA?

I'm currently researching and deciding on a code coverage tool for my company, and have so far tried NCover (Bolt and Desktop), DotCover, and NCrunch. All tools I've tried so far work well for measuring/highlighting code coverage in code called directly by unit tests, but any code called through CSLA (DataPortal_Fetch, for example) is never detected as being covered. As much of our code base resides in these functions, I'm finding the tools to be next to useless for much of what I need tested and measured.
My question then is how can I get code coverage results for CSLA code? Does anyone know of a tool that would work with these kinds of calls, or certain options/extensions I can use to get coverage results with the tools I'm using?
The project is coded in C#, and I'm using Visual Studio 2013 Professional, CSLA 3.8, and .NET 4.0. I have the latest versions of NCover Bolt and DotCover (both on trial), as well as the newest OpenCover that I could find.
Thanks in advance!
NCover Support here.
If you are using NCover Desktop, you can auto-configure to detect any .NET code that is being loaded by your testing (Bolt can only profile test runners).
We have this video that shows auto-detecting NUnit, as an example:
http://www.ncover.com/resources/videos/ncover-creating-a-new-code-coverage-project
And a lot of the same info in this help doc:
http://www.ncover.com/support/docs/desktop/user-guide/coverage_scenarios/how_do_i_collect_data_from_nunit
Please contact us at support#ncover.com if you have extra questions. Hope this helps.
Unlike TyCobb's entirely outdated opinion, current versions of CSLA don't invoke methods via reflection (except on iOS) and haven't since around 2007. But the data portal does use dynamic invocation via expression trees and that's probably the issue causing you trouble.
One option in current versions of CSLA is that the data portal is now described by an interface so you can mock the data portal, potentially creating a mock that does nothing but invoke your DP_XYZ methods directly. Even that's tricky though, unless you make them public and allow other code in your app to easily break encapsulation (yuck). The problem is that you won't be able to call the methods without using reflection, or rewriting the dynamic expression tree invocation code used inside CSLA...
Though perhaps the code coverage tools would see the code executing if it were run via reflection instead of via a runtime compiled expression?

What Behavior Driven Development (BDD) Tooling/Frameworks are available for the Microsoft Stack? [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
We don’t allow questions seeking recommendations for books, tools, software libraries, and more. You can edit the question so it can be answered with facts and citations.
Closed 6 years ago.
Improve this question
I am interested in Behavior Driven Development (BDD)
Are there any good frameworks and/or tooling available for the .Net platform (preferably C# and ASP.Net)?
And when has BDD proved most appropriate to use in real world scenarios? (auxiliary question)
+1 for people's recommendation of SpecFlow for scenarios; never used it but heard many good things about it. I've been using plain old NUnit with a little DSL like this. MSTest would work similarly.
You can also do BDD in the unit space, which is what MSpec is designed to do. I'm personally hating MSpec, but the rest of the team here love it. They like writing examples of how the code works. I like to show why the behavior is valuable. It's a subtle distinction and if you're not worried about doing this at a unit level it won't hit you.
Other frameworks to look at include Concordion, Fitnesse.NET (please put FitSharp behind it!) and TickSpec.
In the real world, the most valuable bit of BDD by a long way is the conversations, not the automated tests. Here's a couple of quick hints and tips for making it work:
Don't write automated tests over things which are in flux. It just commits you to stuff you got wrong. Wait until the UI has settled a bit then do it.
If you don't care much about your UI, but do care about data integrity, write the scenarios over the controller / presenter layer (eg: for admin screens).
Don't start with login. Start by describing a valuable part of the application for which you might log in. Do that first (assume you only have one user). You'll get quicker feedback on the risky bits.
Seek quick feedback on the risky bits, which will usually be the bits which you've never done before. Use scenarios to have conversations around them. Write anything interesting you discover down, but forget the scenarios which are obvious - they're obvious! Don't worry about automating them to start with. Having conversations is more important than writing down conversations is more important than automating conversations.
Good luck! If you want to know more about BDD, I put together a page of relevant links here.
On googling I found Behavior Driven Development (BDD) with SpecFlow and ASP.NET MVC. You might find it useful, take a look. Also go through Behavior-Driven Development with SpecFlow and WatiN
A nice presentation on Pros and Cons of BDD
A channel 9 video Behavior-Driven Development in the Real World
and last but not least an InfoQ article Behavior Driven Development In .NET
LightBDD is an open source framework allowing to write BDD tests that are easy to read but also easy to maintain and extend when project grows larger.
The main features that it offers are:
easy to read scenarios,
easy maintenance of tests,
integration with well known testing frameworks (NUnit / MbUnit / MsTest / xUnit),
scenario steps execution tracking and execution time measurement,
test execution summary report generation in HTML (an example report), XML and plain text format.
It bases on tests that are written purely in code, which means native support for refactoring, code analysis, test running and all other features that Visual Studio / Intellisense / Resharper offers.
An example test written in this framework looks as follows:
[TestFixture]
[FeatureDescription(
#"In order to access personal data
As an user
I want to login into system")] //feature description
[Label("Story-1")]
public partial class Login_feature //feature name
{
[Test]
[Label("Ticket-1")]
public void Successful_login() //scenario name
{
Runner.RunScenario(
Given_user_is_about_to_login, //steps
Given_user_entered_valid_login,
Given_user_entered_valid_password,
When_user_clicked_login_button,
Then_login_is_successful,
Then_welcome_message_is_returned_containing_user_name);
}
}
More information about framework could be found on project wiki page and project main page.
Also MSpec is a good framework.
I use it in the Microsoft stack you mention (C#, ASP.Net and MVC) and I like his syntax.
BDD helps you thinking in business/feature oriented way not just in a code way.
So you are most focused on business value.
It also helps in user acceptance test to create a trust between you and customer.
There is a great tool, called SpecFlow.
SpecFlow is inspired by Cucumber — the well known BDD framework for Ruby on Rails. And has a huge amount of advantages.
You should definitely check it out.
One interesting BDD frameworks is Concordion.NET. It is an open source BDD framework for the Microsoft stack that uses NUnit to execute the Concordion.NET tests: https://github.com/concordion/concordion-net
As Concordion specifications are written in simple HTML, it provides a good basis for a living documentation system. You can use a what-you-see-is-what-you-get (WYSIWYG) editor like BlueGriffon to describe your intended behavior of your software in simple HTML documents and instrument them to verify your system under test.
According to the excellent classification of BDD tools, Concordion.NET focuses on business readable input (and reaches business readable output as well). It moves even beyond BDD and supports ATDD: http://assertselenium.com/2012/11/05/difference-between-tdd-bdd-atdd/
Spec4Net (https://bitbucket.org/fthomsen/spec4net/) is a nice framework too. We use it extensively at work. The learning curve is almost non-existing and the natural flow seems intuitive.

Introduction to unit testing for C#

I'm looking for a good introduction/tutorial for unit testing C#. Most tutorials I've come across so far have either been too basic to be useful or too complex for someone new to unit testing.
(Using Visual Studio 2008 Professional for Windows applications)
Read The Art of Unit Testing by Roy Osherove. It is very good.
Is it just a specific tool for which you're having trouble finding good tutorials? When I was new to the subject I found the NUnit tutorial to be a good starting point:
http://www.nunit.org/index.php?p=quickStart&r=2.4
Rhino Mocks would be good to learn as well to complement the unit testing framework:
https://stackoverflow.com/questions/185021/rhino-mocks-good-tutorials
Perhaps a book? I would recommend you the Pragmatic Unit Testing in C# with NUnit.
It's very complete in my opinion.
It was when I started reading about Moq that I realized unit testing didn't have to be painful. There are some good links near the bottom of the page as to how unit tests can be built with mocking.
One nice thing about using interfaces for controlled coupling and testing is that adding an interface to an existing code base is not a breaking change. I'm adding new features to some legacy code and I've been creating interfaces for existing classes so that the new features can be developed and tested in isolation. It's been working well so far and I plan to continue this style of testing on other projects. For me, the key was to avoid designing complex stub classes with lots of ugly conditional code to expose different cases for my tests. It got to the point where the test code was so complex that I couldn't be sure if it was the code or the test that was broken.

Good resource to learn BDD, TDD (ruby , C#, javascript)

What are the good resource to learn BDD & TDD (ruby , C#, javascript).
What are the good framework using now?
See
Why should I practice Test Driven Development and how should I start?
Beginning TDD - Challenges? Solutions? Recommendations?
Good C# Unit testing book
Introducing BDD
What is the Path to Learn BDD on Ruby On Rails?
Jasmine
Hanselminutes - Understanding BDD and NSpec
I can't really speak with too much authority on this subject, nor will I speak with too greater vigour given how storongly people feel about those two acronyms but it seams as though you are new to BDD / TDD so I will tell you what I wish someonehad told me when I first encoubtered them.
Tests and tools are one component of the overall process and methodology behind TDD, it is arguably one of the more visible aspects and so it is likely that you will see a lot of references to testing being an importabt part of TDD, and it is, I'm just saying, if you are interested in learning about TDD, don't forget the other aspects of it as well.
Resources I have found helpful:
The Pragmatic Programmer: doesn't
really talk about TDD per se, but it
does emphisise a lot of other good
practices that will help you.
Hanselminutes Episode 169
Tools I find helpful
TestDriven.NET - test runner in
visual studio
xUnit.NET - Test Framework
Rhino Mocks - Isolation (mocking)
framework
Here are a few links that may be helpful to you.
What is the most mature BDD Framework for .NET?
Introduction to BDD and Mocking
BDD using NUnit and Moq
RSpec vs Cucumber (RSpec stories)
BDD with Cucumber and rspec - when is this redundant?
NSpec Project Site
Continuous Testing
IMO, the best way to learn these days is with plurasight
http://www.pluralsight-training.net/microsoft/
my boss pays for me and my fellow developer to access the videos, but even if he didnt, its thats good id pay for it myself.

What is the best process for a new ASP.NET web app from the ground up?

I am re-building our poorly designed web application from scratch, and wanted to get into TDD and basically "do things right" as kind of a learning project. What tools, processes, and resources are recommended to do it "right" from the start? I will be working alone as the architect and developer, with the backup of a business analyst and business owners for usability testing and use cases.
EDIT:
Right now we use SourceSafe for source control, is there any reason technologically that I'd want to try to get us to switch to subversion?
EDIT #2:
Looks like the consensus is:
Cruise Control.NET
Subversion(if I want to stop using SourceSafe)
ASP.NET MVC
NUnit for unit testing
Resharper
I highly recommend that you take a look at MVC for ASP.NET if you want to make unit testing a high priority in your development process. It sounds like it is perfect for what you are trying to do.
I would also recommend CruiseControl.NET for continuous integration (this is important if your team is going to grow).
Subversion is my favorite source control system when I am working on small teams. Use Tortoise SVN for Windows Explorer integration.
An answer to your source control question...
Redesigning an app from the ground up will probably be a time-consuming project, I wouldn't waste time changing source control unless you already know exactly which one you will use and have experience setting it up.
Visual SourceSafe gets the job done, especially in a 1 person effort, and its already in place so run with it.
We are using a setup with Visual Studio 2008, Resharper 4.1, Subversion for sourcecontrol, Cruise control for automated builds and the build in unit testing for all our automated tests. and Linq2Sql for or mapping. You could swap out anything but VS (obviously) and resharper (it's so cool) but you could easily use another sourcecontrol, or mapper or unit testing tool.
Here are some tools that can make it easier and safer to work (Googling the names will bring up the relevant pages):
Subversion - Source control
NUnit - Testing framework
CruiseControl.Net - Automated builds
Visual Source safe has a strict locking policy so that only one person can work on a file at a time....CVS or subversion allows multiple users to work on the same file at the same time.
All of the suggestions here are good, but there is no magic bullet. You'll have to look at how big your app is, how many users, how is it deployed, etc. to make your architectural, process, tool set, and other decisions. TDD, for instance, is a good methodology, but not the only good methodology for "doing things right". Another one, CruiseControl is awesome, but in a single developer project, it is probably overkill.
Be consistent in whatever you do is my best suggestion - if you go with TDD, GO WITH TDD if you know what I mean.
We re-wrote our website like you're doing and we are using C# with MVC. Its great. We use Microsoft's SourceSafe to control our code and it works awesome. Since you are the only developer it will depend on what you like.
Microsoft's sourcesafe allows us to create a branch that we can work off can keep under source control, and we can switch between both easily. (I really haven't used subversion to much so I can't comment on it.)
We use NUnit to test/ mock out our code. It super easy to mock them out. We created a class that will save and read the objects.
The save function:
Stream stream = File.Open(simplePath, FileMode.OpenOrCreate);
BinaryFormatter bwriter = new BinaryFormatter();
bwriter.Serialize(stream, actual);
The read function:
Stream stream = File.Open(simplePath, FileMode.Open, FileAccess.Read, FileShare.Read);
BinaryFormatter bwriter = new BinaryFormatter();
object returnObject = bwriter.Deserialize(stream);
We've used NUnit to mock out xml and SQL.
Good luck
If you're about to set up a fresh instance of subversion and continuous integration, starting green from a VSS background, these two free packages will likely save you days (or weeks) of time:
Visual SVN Server
Sets up everything needed for a subversion server, including Windows AD auth and an admin GUI. Free, you may consider supporting their excellent VisualSVN VS addin for source control integration in Visual Studio. Alternatively, can look at AnkhSVN
TeamCity
A Continuous Integration package (alternative to CruiseControl.NET) from JetBrains (makers of ReSharper, a fantastic tool, as mentioned) which is free for the professional version (up to 20 users and 3 build servers).
These two packages are some of the easiest installs around, challenging VSS itself :-)
Using SVN may take a little adjustment; but with the excellent doco for whichever client you pick (AnkSVN, VisualSVN, TortoiseSVN, or some combination), you'll be fine.
Besides, you know where to find people eager to answer any questions you might have in exchange for Rep ;-)
Check out TypeMock or Rhino Mocks. Mocking can save you so much time and pain when you're unit testing a web application.
If you are just starting out then I would change as little as possible (especially since you are the only developer), so stick with Sourcesafe. There is absolutely nothing wrong with it in your situation.
Later down the line, you might look towards the MS Team System, or perhaps go for other 3rd Party tools.
Personally I'm not a fan of Subversion, but I recognise that it's a popular tool across the industry.
As for TDD-specific software, I can't offer any advice. Do you have preferred tools for UML or whatever formal methods you are using?
One thing to mention: Be a 100% sure that you understand what the program's doing and what's it supposed to do, before doing any changes. A 'bad' softwer often turns out to be 'not that bad' after understanding the whole situation.
Sourcesafe can be ok, especially for one person, but when there'll be more and more ppl on the team, the lock model can get annoying, but for the time of being: stick with it

Categories