unit-testing

How to fake a validation error in a MonoRail controller unit-test?

I am running on Castle's trunk, and trying to unit-test a controller-action where validation of my DTO is set up. The controller inherits from SmartDispatcherController. The action and DTO look like: [AccessibleThrough(Verb.Post)] public void Register([DataBind(KeyReg, Validate = true)] UserRegisterDto dto) { CancelView(); if...

programmatic login with .net membership provider

I'm trying to unit test a piece of code that needs a currently logged in user in the test. Using the .Net 2.0 Membership Provider, how can I programmatically log in as a user for this test? ...

Data Driven Unit Tests

What is the best practice for testing an API that depends on data from the database? What are the issues I need to watch out for in a "Continuous Integration" environment that runs Unit Tests as part of the build process? I mean would you deploy your database as part of the build scripts (may be run your installer) or should I go for har...

Unit testing Visitor pattern architecture

I've introduced visitors as one of core architecture ideas in one of my apps. I have several visitors that operate on a same stuff. Now, how should I test it? Some tests I'm thinking of are a bit larger then a unit test should be (integration test? whatever) but I still wanna do it. How would you test code like the C++ sample from wiki ...

Can VS.Net Unit Test be run outside the IDE?

Howdy, Is there a way you can run your UnitTest project against a compiled DLL outside of the IDE? Basically we have testing procedures to validate code before moving into production. I would not want to run the tests inside the IDE. I would want to have the compiled code ready to move to production and be able to run a final test aga...

Unit testing void methods?

What is the best way to unit test a method that doesn't return anything? Specifically in c#. What I am really trying to test is a method that takes a log file and parses it for specific strings. The strings are then inserted into a database. Nothing that hasn't been done before but being VERY new to TDD I am wondering if it is possible ...

How to unit test IDisposable?

I'm working on a piece of library code around IDisposable. The managed path (via using) is easily testable. I'm wondering about the finalizer though: Is calling System.GC.Collect() sufficient to force the finalizer to run? ...

What mutation-testing frameworks exist?

In another question I asked if mutation-testing is useful in practice. As I didn't get any answers that satisfy me, I want to check the current tools myself. So I need an overview about current existing mutation-test-frameworks. Which of them are most usable and why? I program in Java, so I would prefer Java-tools, but I would risk a l...

Using the main method of classes for debugging?

It is good practice to use the main method to test a java/.net class? I've seen it reccommended in some text books, but to me it seems like using a unit testing framework would make more sense... The main method gives you one point of entry to the class and you can test one aspect of the classes functionality. You could I guess test ma...

What do you need to do Unit testing in Java with Eclipse?

I've recently been lifted out of the .Net world into the Java world and I miss my unit tests. Using Visual Studio I used NUnit and TestDriven.net to run my unit tests. What is a comparable system for Java Using Eclipse? I'm looking specifically for the plugins that will get me going, or a guide on how to do it. I'm aware that JUnit i...

Should unit tests be written before the code is written?

I know that one of the defining principles of Test driven development is that you write your Unit tests first and then write code to pass those unit tests, but is it necessary to do it this way? I've found that I often don't know what I am testing until I've written it, mainly because the past couple of projects I've worked on have more...

How do I trap OCUnit test pass/failure messages/events.

I'm trying to use xcodebuild and OCUnit with my Continuous Integration server (TeamCity). JetBrains offers test observer implementations for boost::test and CppUnit that format test output in a way that TeamCity can interpret. I need to do something similar for OCUnit if I want to use it. There appears to be a SenTestObserver class ...

Is there a free Visual Studio addin for Nunit?

I'm cheap and don't want to pay for ReSharper or TestDriven.NET, is there a free visual Studio addin for NUnit? ...

Writing a unit testing framework for testing SQL stored procedures

Today I had an idea of writing a unit testing framework for stored procedures in MySQL. The full idea is written on a recent post on my blog. In short it goes like this: I want to automate my procedure testing, I want to use a standardized way to test my procedures. Unit testing is widely documented, and there are a zillion XUnit framew...

Unit testing that an event is raised in C#

I have some code that raises PropertyChangedEvents events and I would like to be able to unit test that the events are being raised correctly. The code that is raising the events is like public class MyClass : INotifyPropertyChanged { public event PropertyChangedEventHandler PropertyChanged; protected void No...

Changing Output path of the Unit Test project in Visual Studio 2008

I changed the output path of the test project, because the default path doesn't conform to our projects directory structure. After I did that, Visual Studio 2008 fails to run the tests, because it can't find the Unit Test project assembly. What else do I have to change for the Unit Test Engine to find the assembly? ...

Best practices to test protected methods with PHPUnit

Hello, I found the discussion on Do you test private method informative. I have decided, that in some classes, I want to have protected methods, but test them. Some of these methods are static and short. Because most of the public methods make use of them, I will probably be able to safely remove the tests later. But for starting with ...

How do you test private methods with NUnit?

I am wondering how to use NUnit correctly. First i created a separate Test-Project that uses my main project as reference. But in that case i am not able to test private methods. My guess was that i need to include my testcode into my main code?! - That doesn't seem to be the correct way to do it. (I dislike the idea of shipping code wit...

System.UnauthorizedAccessException when running a test in VS2008

When I run selenium tests (written as nunit tests) from VS2008 I am getting System.UnauthorizedAccessException : Access to the path /bin/Debug is denied. The test is trying to read a entry in App.Config( this file is copied to bin/Debug during compilation). I used unlocker to check file handles and it is VS2008 that has a handle to that ...

Parsing HTML Fragments

What's the best way to parse fragments of HTML in C#? For context, I've inherited an application that uses a great deal of composite controls, which is fine, but a good deal of the controls are rendered using a long sequence of literal controls, which is fairly terrifying. I'm trying to get the application into unit tests, and I want to...