tdd

How do you unit test a unit test?

I was watching Rob Connerys webcasts on the MVCStoreFront App, and I noticed he was unit testing even the most mundane things, things like: public Decimal DiscountPrice { get { return this.Price - this.Discount; } } Would have a test like: [TestMethod] public void Test_DiscountPrice { Product p = new Product(); ...

How do I inject a WebRequest/Response dependency?

I'm struggling to separate the dependencies in the following code: public static SiteConnector ConnectToSite(String Logon, String Password) { HttpWebRequest webRequest = (HttpWebRequest)WebRequest.Create(_URI); ConfigureRequest(Logon, Password, webRequest); HttpWebResponse webResponse = (HttpWebResponse)...

How do you balance Framework/API Design and TDD

We are building a framework that will be used by other developers and for now we have been using a lot of TDD practices. We have interfaces everywhere and have well-written unit tests that mock the interfaces. However, we are now reaching the point where some of the properties/methods of the input classes need to be internal, and not v...

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...

Why are TDD 'Spikes' called 'Spikes?

The test driven development guys refer to a quick, exploratory, investigation that involves coding something up to see if it works, a spike. Any ideas why they came up with that word? Update: The coinage by Kent Beck looks like the 'original' one to me, although his usage of the word doesn't make much sense in my opinion. Coding up a q...

How do you unit test private methods?

I'm building a class library that will have some public & private methods. I want to be able to unit test the private methods (mostly while developing, but also it could be useful for future refactoring). What is the best way to do this? ...

How far do you take code coverage?

I've recently started using code coverage tools (particularily Emma and EclEmma), and I really like the view that it gives me as to the completeness of my unit tests - and the ability to see what areas of the code my unit tests aren't hitting at all. I currently work in an organization that doesn't do a lot of unit testing, and I plan on...

How does TDD make refactoring easier?

I've heard that projects developed using TDD are easier to refactor because the practice yields a comprehensive set of unit tests, which will (hopefully) fail if any change has broken the code. All of the examples I've seen of this, however, deal with refactoring implementation - changing an algorithm with a more efficient one, for examp...

Debugging is a bad smell - how to persuade them ?

I've been working on a project that can't be described as 'small' anymore (40+ months), with a team that can't be defined as 'small' anymore (~30 people). We've been using Agile/Scrum (1) practices all along, and a healthy dose of TDD. I'm not sure if I picked this up from Agile or TDD, more likely a combination of the two, but I'm now ...

Best way to do TDD in express versions of visual studio(eg VB Express)

I have been looking in to doing some test driven development for one of the applications that I'm currently writing(OLE wrapper for an OLE object). The only problem is that I am using the express versions of Visual Studio(for now), at the moment I am using VB express but sometimes I use C# express. Is it possible to do TDD in the exp...

Building and running C++ unit tests in Visual Studio (TDD)

I have a large project for which I am attempting to use TDD. I am using Tut as my test framework, which has its flaws but is sufficient for what I need. I need to exploit link time test seams, each test must be in its own executable. The project for this executable then launches itself as a post build step. Unfortunately, this means t...

How would I do TDD with a COM OLE object

I have an OLE COM object that trying to write a wrapper for, I have decided to start to use TDD to write the code for it as I believe that it will give me a better sense of direction with what I'm try to write. The COM object has a interface like this: Interface Mapinfo Sub [Do](ByVal cmd As String) Function Eval(ByVal cmd As S...

What best practices do you use for testing database queries?

I'm currently in the process of testing our solution that has the whole "gamut" of layers: UI, Middle, and the omnipresent Database. Before my arrival on my current team, query testing was done by the testers manually crafting queries that would theoretically return a result set that the stored procedure should return based on various r...

How do you measure the quality of your unit tests?

If you (or your organization) aspires to thoroughly unit test your code, how do you measure the success or quality of your efforts? Do you use code coverage, what percentage do you aim for? Do you find that philosophies like TDD have a better impact than metrics? ...

Engineer accountability and code review processes

In your “enterprise” work environment, how are engineers held accountable for performing code inspections and unit testing? What processes do you follow (formal methodology or custom process) to ensure the quality of your software? Do you or have you tried implementing a developer "signoff" sheet for deliverables? Thanks in advance! ...

How does MbUnit work with VS 2008

I set up MbUnit and have been trying to get it to work with VS 2008 using the MbUnit GUI but every time I run a test it closes and I get a this program needs to close error. I had a similar problem with Gallio where I got a runner exception every time I ran a test. Do I need an addin for VS like testDriven.Net to get this to work? ...

How do I get autotest to properly inflect singular models and plural controllers

Just as an example, if I have a Book model and a BooksController, autotest, part of the ZenTest suite will pick up the association between the two and load test/unit/book_test.rb and test/functional/books_controller_test.rb into the test suite. On the other hand, if I have a Story model and a StoriesController, autotest refuse to "notice...

Unit tests vs integration tests with Spring

I'm working on a Spring MVC project, and I have unit tests for all of the various components in the source tree. For example, if I have a controller HomeController, which needs to have a LoginService injected into it, then in my unit test HomeControllerTest I simply instantiate the object as normal (outside of Spring) and inject the pro...

How do I write unit tests in PHP?

I've read everywhere about how great they are, but for some reason I can't seem to figure out how exactly I'm supposed to test something. Could someone perhaps post a piece of example code and how they would test it? If it's not too much trouble :) ...

Rhino Mocks: Asserting that a method is called exactly one time

I want to assert that a method is called exactly one time. Update: I'm using RhinoMocks 3.5. Here's what I thought would work: [Test] public void just_once() { var key = "id_of_something"; var source = MockRepository.GenerateStub<ISomeDataSource>(); source.Expect(x => x.GetSomethingThatTakesALotOfResources(key)) ...