tdd

Code works but test fails

I have a test that's failing even though the operation actually works when I test it in the browser. Something wrong with my test, looks like. I'm using Shoulda and fixtures. require 'test_helper' class AddressesControllerTest < ActionController::TestCase context 'on PUT to :update' do setup do put(:update, { :id...

Using old code to verify results in unit tests

Lets says I'm replacing an over complicated method with a much simpler implementation that I believe does the same thing. Would it make sense for me to copy the old code into a class with my unit tests so I can assert the result of both is the same? Thanks ...

Simulate/Generate a SocketTimeoutException in a servlet

Hi all, I'm working a web project that use: - Java - Jetty - Fitnesse tool - etc.. I have a difficulty to simulate/generate a SocketTimeoutException, more info below: The use-case-simplified: I wrote a API that make calls to a host(WebServer). In the source-code if I receive a RemoteException and is a SocketTimeoutException, I nee...

Usage of Assert.Inconclusive

Hi, Im wondering how someone should use Assert.Inconclusive(). I'm using it if my Unit test would be about to fail for a reason other than what it is for. E.g. i have a method on a class that calculates the sum of an array of ints. On the same class there is also a method to calculate the average of the element. It is implemented by ca...

Using Jeremy Mcanally's context for testing in Rails 2.3.x

I'd like to try out Jeremy Mcanally's context gem for testing: http://github.com/jeremymcanally/context/tree/master It does not work out of the box with Rails 2.3.x, anyone got it working? EDIT hi mike, tx for ur help. i installed the gem like u said, and have added "require 'context'" to test_helper.rb however, it stil doesn't seem t...

Moq with WinForms MVP Pattern - Failing Test

Hi all - I'm learning TDD and the MVP pattern. I've created a simple WinForms app that's like a replacement for the TOAD SQL tool. I'm trying to go back and write tests now for the code I've already written (which I know isn't the correct process for TDD, but please bear with me). In my test class for the form, I want to test the conc...

Looking for Great Example Java Application in MVC or MVP

I'm going to be delivering a presentation to my company regarding MVC, MVP and MVVM patterns, test-driven development, and ORM solutions. I'm a .Net programmer and have found the NerdDinner application to be a nice example app to illustrate MVC, TDD and ORM. Is there a good example app in the Java world to demonstrate MVC or MVP with J...

I do not write tests. Am I stupid?

I've done a little bit of reading on unit testing and TDD, and I've never seriously considered writing tests to such a precise extent. Granted, I am not working on any projects that are ridiculously huge. If all I build are small apps, am I stupid for not writing tests? Edit: To clarify, when I say "small apps", I mean apps that are ...

TDD. test first anyway?

Are you doing test first anyway? Or in some cases you are doing some coding and then writing your tests to make sure code works? As for me I prefer to create a class. Sure, during class creation I think about its interface and how to test the class. But I dont write testing code first. Do you write it first? Do you think you should alway...

How do I get sufficient detail in planning and estimation when using TDD?

When planning a 2-week iteration in the past I have taken a user story: Story: Rename a file And broken it into tasks which were then estimated in hours: Story: Rename a file Task: Create Rename command (2h) Task: Maintain a list of selected files (3h) Task: Hook up to F2 key (1h) Task: Add context menu option (1h) I would then...

Unit testing screen scraper

I'm in the process of writing an HTML screen scraper. What would be the best way to create unit tests for this? Is it "ok" to have a static html file and read it from disk on every test? Do you have any suggestions? Thanks ...

how to phrase the result of an action in BDD/TDD

The title is probably not very clear. I have the following example in mind: an Authenticator object authenticates a user using credentials. It returns a AuthResult object. This AuthResult object says the authentication succeeded, or that it failed (and if so, why it failed, eg username not found). How can I phrase this in a test? 'test...

Unit Testing Front End Logic

We have tried to introduce unit testing front end logic on a recent project and the value of the tests are being questioned. We were not code reviewing the tests so the quality of them is poor, developers copied poor tests creating more poor tests and so we have a lot of crap tests. I still believe there is value in testing the prese...

How do I make TDD in Visual Studio less painful?

I've become a bit of a TDD zealot lately. Explaining the concept isn't the hard part. Most people respect the purpose behind it. However, when I try to demonstrate the actual process behind the idea, the biggest complaint is: "When I'm writing my initial tests, I hate how Visual Studio intellisense tries to guess what I'm doing....

BDD/TDD: can dependencies be a behavior?

I've been told not to use implementation details. A dependency seems like an implementation detail. However I could phrase it also as a behavior. Example: A LinkList depends on a storage engine to store its links (eg LinkStorageInterface). The constructor needs to be passed an instance of an implemented LinkStorageInterface to do its jo...

testing objects using DAO

Continuing another but similar question about testing (see here). I'll use a similare example (pseudocode) class LinkDisplayer method constructor(LinkStorage) method displayLatestLinksByCategory(number_of_them) class LinkStorage method saveLink(Link) method retrieveLatestLinksByCategory(category, number_of_them) class ...

Should I change code to make it more testable?

Hi, I often find myself changing my code to make it more testable, I always wonder whether this is a good idea or not. Some of the things I find myself doing are: Adding setters just so I can set an internal object to a mock. Adding getters for internal maps/lists so I can check the internal state of the object has changed after perf...

Unit tests on MVC validation

How can I test that my controller action is putting the correct errors in the ModelState when validating an entity, when I'm using DataAnnotation validation in MVC 2 Preview 1? Some code to illustrate. First, the action: [HttpPost] public ActionResult Index(BlogPost b) { if(ModelState.IsValid) { ...

Is unit testing a bad idea during beta/prototyping?

A new project we began introduced a lot of new technologies we weren't so familiar with, and an architecture that we don't have a lot of practice in. In other words, the interfaces and interactions between service classes etc of what we're building are fairly volatile, even more so due to internal and customer feedback. Though I've alway...

What design models to create before TDD?

Summary: What models and diagrams have you included and/or delivered in your TD -design vs -development, and why? Details: New 4-developer project, in a shop where we're gradually making progress in getting management to graduate from "buy in" to "action" in the TDD adoption/expectation. I'm (a developer) wanting test-driven design f...