unit-testing

How to get model data from a ViewResult in ASP.NET MVC RC1?

Given the following controller class: public class ProjectController : Controller { public ActionResult List() { return View(new List<string>()); } } How can I get a reference to the model object in the following unit test? public class ProjectControllerTests { private readonly ProjectController controller; ...

least 'worth it' unit test you've ever written?

On the SO blog and podcast Joel and Jeff have been discussing the, often ignored, times when unit testing a particular feature simply isn't worth the effort. Those times when unit testing a simple feature is so complicated, unpredictable, or impractical that the cost of the test doesn't reflect the value of the feature. In Joel's case,...

Unit testing code that uses PortalSiteMapProvider

I have a web part that uses PortalSiteMapProvider to query the Sharepoint navigation hierarchy, but unit tests written for that code fail, because the code is being run outside the Sharepoint context and thus no site map providers are available. I've identified two alternate ways of solving this dilemma: Because Sharepoint is basicall...

.NET assemblies spanning multiple files and unit testing

Can anyone point me to some information on .NET assemblies spanning multiple files? I've found this remark on MSDN (here): Although it's technically possible to create assemblies that span multiple files, you're not likely to use this technology in most situations. I'm asking because I have the business logic and the unit test...

Why do you use .proxy() in JMock?

Hi, I'm trying to learn how to use JMock and I'm a bit confused about what you use the .proxy() method for. I know its invoked on your Mock class but I don't understand what its puprose is. I haven't had any luck finding a good description about how it works on google. Any help is much appreciated. ...

Which Method of Model Binding Has Best Unit Test Semantics in ASP.NET MVC?

Definitions In ASP.NET MVC, there are two ways to do model binding in an action. Let's call these the "Bind arguments way" and the "UpdateModel way." Both of them do almost exactly the same thing, and they do it in almost exactly the same way: public ActionResult UpdateWithBindArguments(Foo model) { Repository.Update(mo...

Type of Projects where Unit Testing is useless

Do you believe that Unit Testing (and test driven development) must be done under any set of circumstances or should there be some exceptions. I've been working on the type of projects lately where I can't see how Unit Testing would be useful or improve design, quality of code, etc. One type of project is PDF reports generator which tak...

Does adding member functions to Test Fixtures indicate a poor test?

My test fixtures often have "setup" member functions that cannot be called during construction of the fixture since they have parameters that will change based on the tests that will be run. They are written to avoid code duplication. Are these functions creating an invalid test because they rely on complex, non-production means of bein...

Best practices for unit testing Android apps

I'd like to unit test my Android application but I found that test driven development in Android is far from trivial at the moment. Any tips, tricks, war stories for building light weight and preferably fast running tests? ...

Practical refactoring using unit tests

Having just read the first four chapters of Refactoring: Improving the Design of Existing Code, I embarked on my first refactoring and almost immediately came to a roadblock. It stems from the requirement that before you begin refactoring, you should put unit tests around the legacy code. That allows you to be sure your refactoring di...

Best framework for Unit-Testing some legacy ASP.NET 1.1 code

I have legacy asp.net 1.1 website. It has a very poor VB layered achitecture. Debugging takes about 10 minutes to run the credit card processing tests. I'd like to add some unit testing capabilities to the solution to check my changes. I was thinking about using mbunit with galleo. Will mbunit and galleo work with my .net 1.1 code...

How do you mock the session object collection using Moq

I am using shanselmann's MvcMockHelper class to mock up some HttpContext stuff using Moq but the issue I am having is being able to assign something to my mocked session object in my MVC controller and then being able to read that same value in my unit test for verification purposes. My question is how do you assign a storage collection...

Ruby Unit::Test comparing html output by ignoring whitespace

Hi All, I am using Ruby's Test::unit to compare the result of generated html with the expected result. (not using rails). I am not concerned with whitespace differences but these nearly always crop up during tests. Is there any testing mechanism to compare html while ignoring meaningless whitespace. I can see there's similar question f...

Why are all my Visual Studio test results "Not executed"

When I run my unit tests in my project I am seeing a result "Not executed" for every one. I have restarted my computer so I doubt this is some kind of hung process issue. Google has revealed nothing. Does anyone have any ideas? ...

How to unit test F# code in Visual Studio 2008?

I'm new to F# and I intend to create new F# project, and unit test it with F# in Visual Studio 2008, but the Visual Studio 2008 Unit Test Wizard don't have a F# test project option (just have C, C# and VB options). Is it possible to unit test F#? Is it possible to unit test F# with a F# test project? Is it possible to unit test F# with...

What are the most important things to test in an ASP.NET MVC application?

Most of the stackoverflow posts about ASP.NET MVC unit testing talk about a specific issue or specific thing to test such as testing HtmlHelpers. Others on the subject of best practices have surprisingly few answers. Available videos I have watched are completely useless in my opinion - and mind blowingly long (by the time you've watched...

What should be done first: Code reviews or Unit tests?

Hello, If a developer implements code for some module and wants to get it reviewed. What should be the order : *First unit test the module after designing test cases for the module, debugging and fixing the bugs and then give the modified code for peer code review (Pros- Code to be reviewed is 'clean' to a good extent. Reduces some a...

How To Write CRUD Unit Tests for Moq and Linq-to-Sql

I am just getting involved in Moq and unit testing, so forgive me if this seems obvious (a quick search through SO didn't show me anything like this). I have an interface with the following proposed member: void AddFeed(Feed feed); That I would like to write a unit test for this functionality. The test class has a Moq Repository decl...

Help me pick a book on design patterns, refactoring, and/or testing

My role at my company is the sole developer, and my experience is limited (I got the job mostly because I'm probably the only person who will do it for the money they're willing to pay - but I digress) compared to the averge developer but more extensive than the average recent grad. As such I'm looking for some good books to fill in the...

Besides "all of them" as an answer, what type of applications (be specific) have had true success with unit testing?

What type of applications did you use this TDD, unit testing approaching (web app, compiler, rails, etc?). What language was your application written in? Did you use a preexisting unit testing frameworking like junit or nunit or did you you rollo your own. Did you use automatically code generate your test cases or was most of the work t...