unit-testing

Unittesting Url.Action (using Rhino Mocks?)

I'm trying to write a test for an UrlHelper extensionmethod that is used like this: Url.Action<TestController>(x => x.TestAction()); However, I can't seem set it up correctly so that I can create a new UrlHelper and then assert that the returned url was the expected one. This is what I've got but I'm open to anything that does not inv...

Writing a testable "import data from database" class

I am tasked with pulling all the rows from a 3rd party vendor's SQLite data table, creating business objects from those records, and sending the new business objects off to another class. Pseudo-code: var databasePath = "%user profile%\application data\some3rdPartyVendor\vendor.sqlite" var connection = OpenSqliteConnection(databasePath...

How can I instantiate an asp.net codebehind class in a test harness?

I'm working on a web site written using asp.net WebForms. I'd like two wrap test cases around some of the more interesting subroutines. How can I instantiate the class that comes from the .aspx file in my test project so I can manipulate it under nUnit? ...

Unit Testing a Login in ASP.NET

I'm very new to TDD and I'm having trouble with one of my unit tests. I just can't seem to understand what to do next. :( I'm trying to unit test a service of mine called AccountService and I'm testing a method called DoLogin(username, password). Here's some example code: [Test] public void User_With_Correct_Username_And_Pass_Sh...

how to interpret this (rhino) mock unit test failure msg

I am trying to test that a method to load a UI matrix is being loaded properly. The test fails unless I tell the mock framework to ignore the argument passed, giving me the following message: Rhino.Mocks.Exceptions.ExpectationViolationException : ITimeSheetMatrixWidget.Load (Smack.ConstructionAdmin.Domain.TransferObjects.TimeSheetDtoAss...

Elegant method to test validates_associated in Rails Unit Tests?

Seems like this should be findable with a couple of Google searches...but no luck. I'm looking for an elegant approach to testing validates_associated in my models, such as... class Network < ActiveRecord::Base ... validates_associated :transporter ... end And the test: class NetworkTest < ActiveSupport::TestCase test 'should no...

Code Coverage Tools for Scala

What are the available code coverage tools for Scala? I have Scala spec tests and a Hudson continuous integration set-up. Is there something I can hook-in to this setup to measure and track code coverage? ...

Recommendations for an open-source project to help an experienced developer practice C++

I'm looking for recommendations for open-source projects written in C++ that will help me "get my chops back". A little background: I've been working heavily in Java for the last three years, doing a lot of back-end development and system design, but with a fair amount of work in the presentation layer stuff, too. The last C++ project...

Unit testing for invalid enum value

I have a lump of code that looks a bit like this: If mode = DiaryMode.Admin Then modeObject = DBNull.Value ElseIf mode = DiaryMode.Academy Then modeObject = ApplicationSettings.Academy ElseIf mode = DiaryMode.Scouting Then modeObject = ApplicationSettings.Scouting Else Throw New NotSupportedException() End If The idea ...

Unit Testing data from DB2

I have a .NET project (Test project) in VS2008 and am doing some unit tests for the data in DB2. I am finding that the tests are not transactional and I have to phyiscally go and delete the data or run a function to clean the data before I run the test even though I am using ITransaction. Can any one point why? ...

Silverlight Unit Testing (databinding, MVVM)

Hi all, How would you suggest I write a unit test to check that a UI object is bound to a particular named property in my ViewModel? Thanks, Mark ...

Unit testing patterns for microcontroller C code

Although there are plenty of unit test frameworks that support C, I'm a little stumped on how to write unit tests for micro controller code (PIC in my case, but I think the question is more general than that). Much of the code written for micro controllers revolves around Writing configuration and data values to registers, reading incom...

Recommended unit test framework for new .NET projects

I'm about to start a new C# application, which will probably take some while (read: > 1 year). I want to keep it cross-platform, that is, it should work using Mono, but my primary development platform is Visual Studio. Now I'm looking into the test frameworks, but I wonder which one you would take for both being portable and reliable in...

Theory vs Test Nunit

I was just reading through the Nunit 2.5 docs and came across the [Theory attribute], and I'm having a little bit trouble understanding how this is different to a normal unit test and how it could be used. What makes it different from a normal test? What situations would you use this kind of test? I just can't seem to get my head arou...

Should mock objects dispatch events?

I'm using this kind of wiring for my MVC and I want to test the controller. So far, I've found two ways : either my mock view dispatch events or my controller expose public methods. Dispatching events seems the way to go (as pointed out in an answer), but if my view is a simple mock object, how do I dispatch those events? ...

How Much Should Each Unit Test Test?

How much should each of my unit tests examine? For instance I have this test [TestMethod] public void IndexReturnsAView() { IActivityRepository repository = GetPopulatedRepository(); ActivityController activityController = GetActivityController(repository); ActionResult result = activityController.Index(); Assert.IsInst...

Avoid Database Dependency For Unit Testing Without Mocking

I've got many objects with methods that require database access. We're looking to get into unit testing but are keen to avoid the use of mock objects if possible. I'm wondering if there is a way to refactor the Validate method shown below so that it wouldn't need db access. In the actual application there is usually a fair bit more going...

Do you have the time to write Unit tests?

In your daily work, do you really have the time to write unit tests? In a lot of cases when implementing a new feature it seems that things work fairly well and we could now hand it off to the testers. Writing and maintaining unit tests often seems to take too much time. ...

Helping getting started using Boost.Test

I am trying to start unit testing. I am looking at a few C++ frameworks and want to try Boost.Test. The documentation seems very thorough, and it's a bit overwhelming, especially someone new to unit testing. So here's a situation that I want: Let's say I have 2 classes, Foo and Bar. I want to write a suite of tests for Foo and a suite o...

Configure Eclipse to run my FlexUnit tests automatically

I'd like to set up my projects in Eclipse to run FlexUnit tests everytime I save my work. I found an example with JUnit here : http://misko.hevery.com/2009/05/07/configure-your-ide-to-run-your-tests-automatically/ How would you do it? Is it possible to run FlexUnit tests without Flash Player? ...