unit-testing

How to test asp.net membership, profile, roles with VS Test Framework?

Hey all, We're getting some errors, if we try to test something with the asp.net membership framework. It seems that it can't instantiate the asp.net membership environment and so, it can't access all the profiles, users and so on. Has anybody seen a similar problem? Or is it working for someone? Cheers, Steve ...

How do I prevent generic arguments from being messed up by VS2008 unit testing

I have two classes like this (in the actual project): namespace app { internal class A { } internal class B { private List<A> list; private void SomeMethodToTest() { list = new List<A>() { new A() }; } } The I have my Unit test looking something like [TestClass()] public class ATes...

How unit testing a singleton in obj-c?

I have a singleton class, and can't unit test their code. I have test like: Db *db = [[Db alloc] initWithName:@"sample.db"]; [db createDb]; STAssertEquals([db existDb],YES,@"The db is not created!"); But only work the first. When the second is executed, I always get "null" from the initWithName method. When I remove the singlet...

How do you write a unit test to test an ASP.NET web forms application for CSRF vulnerability?

We have an ASP.NET web forms application that is probably vulnerable to Cross-site request forgery (CSRF) attack. How do we begin to write a unit test that will alert us to this? Using NUnit. Some tips or pointers would be great. ...

How do I run NUnit in debug mode from Visual Studio?

I've recently been building a test framework for a bit of C# I've been working on. I have NUnit set up and a new project within my workspace to test the component. All works well if I load up my unit tests from Nunit (v2.4), but I've got to the point where it would be really useful to run in debug mode and set some break points. I've tr...

How can I validate wpf bindings are going to real properties?

I would like a simple way to ensure that all bindings I've declared in my xaml files go to real properties. Even better, I'd like to instantiate my wpf window in a unit test and call a method to ensure that the bindings are correct. Unfortunately, wpf doesn't even throw an exception if I have something wrong. That leaves me the burden...

nHibernate logging during unit testings

I'm running unit tests from inside VS2008 against a nHibernate application and would like to turn on logging during the unit tests so I can see a bit more of what is going on. I've copied and pasted another application's app.config that successfully logs nhibernate information into the unit tests app.config, but still don't get any outp...

How should I unit-test a simple CRUD-class?

I am right now trying to do very, very simple stuff with unit-testing in VS2008, to get started and get a feel for this. I think I have testing of small non-database stuff down, but now I want to start testing my real solutions - that are almost always CRUD-heavy. So let's assume I have a class in the data-access layer, that does standa...

Dealing with DependencyObjects in Silverlight Unit Tests

I have been writing unit tests using NUnit and Moq with my Silverlight code for some time now. One problem I keep running into has to do with DependencyObjects. If anything is derived from DependencyObject, then I can't instantiate it in my test. For instance, MouseEventArgs derives from DependencyObject. If I have code that takes th...

Debugging unit tests with resharper

Hi, I've just started using resharper and I found a very annoying thing about it. When debugging a unit test, I try to step-into (F11) a method, but visual studio complains that source code is not available. The problem is that resharper is wrapping method calls with its own classes. Of course I can put a braeakpoint further in my source...

Moq - How to unit test changes on a reference in a method

Another day , another question. My service layer has the following method public MatchViewData CreateMatch(string user) { var matchViewData = !HasReachedMaxNumberOfMatchesLimit(user) ? CreateMatchAndAddToRepository(user) : MatchViewData.NewInstance(new Match(user)); matchViewData.LimitReached = HasReachedMaxNum...

Unit Testing - Is this the 'right' way or the 'wrong' way?

If you were testing a count function like the one below, is it considered to be 'right' or 'wrong' to test multiple things for the function in one function vs having a test function for each of the tests? function testGetKeywordCount() { $tester = $this->getDatabaseTester($this->CompleteDataFile); $tester->onSet...

Is it bad practice to have more than Assert in a unit test?

Is it bad practice to have more than Assert in a unit test? Does it matter? ...

Data Driven Testing with Ruby's Test::Unit for Selenium

I'm pretty new to both Ruby and Selenium and I'm just trying to figure out the best way to build my test harness. I'm using Rake, Rake::TestTask, and Test::Unit to power this. I have a suite that I'd like to run once for each browser/os combination. I can't figure out how to parameterize my tests though, something I've become accustomed ...

Testing time sensitive applications in Python

I've written an auction system in Django. I want to write unit tests but the application is time sensitive (e.g. the amount advertisers are charged is a function of how long their ad has been active on a website). What's a good approach for testing this type of application? Here's one possible solution: a DateFactory class which provi...

Who is responsible for attaching listeners in a no-initialization dependency injection scheme?

I've been reading through Misko Hevery's Guide: Writing Testable Code. I definitely buy into dependency injection as a great tool to improve testability, and use it a lot in my code. However, when reading the first part of the guide "Flaw #1: Constructor does Real Work", I find I'm still a bit fuzzy on how you're supposed wire up event...

Assert.ReferenceEquals() Passes where Object.ReferenceEquals() returns 'false' in Visual Studio Test

In attempting to create an initial, failing unit test in Visual Studio Professonal 2008's test capabilities, I can't seem to get Assert.ReferenceEquals() to correctly fail when an object instance is not equal to a null reference. Note that object.ReferenceEquals() is correctly returning false for this same comparison. Here is my class c...

Can invariant testing replace unit testing?

As a programmer, I have bought whole-heartedly into the TDD philosophy and take the effort to make extensive unit tests for any nontrivial code I write. Sometimes this road can be painful (behavioral changes causing cascading multiple unit test changes; high amounts of scaffolding necessary), but on the whole I refuse to program without ...

How do I break this down into Unit Tests?

I have a method that is called on an object to perform some business logic and add it to the database. The object is a Transaction, and part of the business logic requires searching the databses for related accounts and history items on the account. There are then a series of comparisons and operations that need to bring back informati...

What to test in unit testing, a method or a scenario ?

What to test in unit testing, a method or a scenario? If test each method then minimal test case setup is required. If test a method which calls other methods then setup required for the test case is huge. If unit-tests for the individual methods are already there then why to write for this method which is using them? But then it al...