tdd

Leaf classes in the dependency graph can only be tested for state?

So, I was thinking and I came into the conclusion that when Unit-Testing, even if one wants to base mainly in behaviour-type testing (that is, with mocks, for example), I will eventually always to have to do state-based testing at least for the leaf classes (in the dependency graph). Is this correct? PS: I am, of course, excluding stab...

Couple of questions about unit-testing

Let's assume we are designing a Stack class test-first (TDD): public class Stack<T> { private T[] elements = new T[16]; private int size = 0; ... } This Stack makes use of a size 16 internal array to store its elements. It will work fine until you need to add a 17th element. As I might need a 17th element, I decided to add...

How to conciliate TDD with SUT interface's contracts?

Assuming we are implementing using TDD a Stack class, we would need, for each bit of functionality of our Stack class, to add a new test that exercises it: [TestMethod] public void Should_Be_Empty_After_Instantiation() [TestMethod] public void Should_Not_Be_Empty_After_Pushing_One_Item() ... Now, on the other hand, when doing Unit-Tes...

Pattern for creating a graph of Test objects?

I have to write Unit Tests for a method which requires a complex object Graph. Currently I am writing a Create method for each Test as shown below. 1. private static Entity Create_ObjectGraph_For_Test1() 2. private static Entity Create_ObjectGraph_For_Test2() ...... And So on The create method has about 10 Steps and they might vary by...

Asserting set up and pre-conditions in Unit Tests

Is having more than one assert per test a really bad smell? I usually try to follow the “arrange, act, assert” pattern as well as the single assert per test guideline. I think having clean, small, isolated tests is pure awesomeness. For the most part I manage to do this. However, sometimes I find myself asserting “pre-conditions” right...

What failure modes can TDD leave behind?

Please note I have not yet 'seen the light' on TDD nor truly got why it has all of the benefits evangelised by its main proponents. I'm not dismissing it - I just have my reservations which are probably born of ignorance. So by all means laugh at the questions below, so long as you can correct me :-) Can using TDD leave yourself open to...

rspec asserting encrypted password not plain text

How would I write a test in rspec to ensure passwords are not stored as plain text in my Ruby on Rails application? I don't really care about the implementation yet as I don't know exactly what plugin or how I am going to write the password encryption (there are lots of examples). I just want a failing test that's independent of the ...

Anyone done an Objective-C Xode version of Osherove´s TDD Kata "String Calculator"?

Always trying to code better and I am interested in doing TDD for Objective-C and Xcode. Do you know any post that implement something like Roy Osherove´s "String Calculator"-Kata Update: trying to find out how to speed up TDD on iOS ...

should i only be testing public interfaces in BDD (in general, and specifically in ruby)

I'm reading through the (still beta) rspec book by the prag progs as I'm interested in behavioral testing on objects. From what I've gleaned so far (caveat: after only reading for 30 min) the basic idea is that I want ensure my object behaves as expected 'externally' ie. in its output and in relation to other objects. Is it true then t...

Factory_girl or machinist?

Are you using factory_girl or machinist for stubbing/mocking in Rails tests? ...

How can I use unit testing when classes depend on one another or external data?

I'd like to start using unit tests, but I'm having a hard time understanding how I can use them with my current project. My current project is an application which collects files into a 'Catalog'. A Catalog can then extract information from the files it contains such as thumbnails and other properties. Users can also tag the files with...

TDD with filesystem dependencies

Hello. I have an integration test LoadFile_DataLoaded_Succefully(). And I want to refactor it to the unit test for breaking dependency with filesytem. P.S. I am new in TDD: Here are my production class : public class LocalizationData { private bool IsValidFileName(string fileName) { if (fileName.ToLower().EndsWith("...

Implementing User Stories the Agile Way

I'm a newbie to the Agile/TDD world and trying to get my head around some of the basics. This is related to the way I should go about implementing user stories. For e.g. lets assume I have below 2 user stories to start with for a hypothetical content management system: Story 1: As a Content Author I need to be able to create News Arti...

Evidence based studies on the topic of best programming practices?

When seeking advice on good programming practices the typical answers are a variation of agile software development, test driven development or design patterns. However, as far as I know, neither of these are proven using the scientific method (if I'm wrong on this then feel free to correct me). I wonder, are there any good resources on...

How to move from .NET-style TDD to Ruby?

I've been struggling to adapt my standard approach for test-driving .NET code to Ruby. As an example, I am writing a class that will: grab all *.markdown files from a directory foreach file: extract code samples from file save code to file.cs in output directory Normally for .NET I'd end up with something like: class Examp...

Rails 2.3.8 is not loading my 'lib' folder during tests!

How do I get Rails to load my lib folder during tests?? Rails 2.3.8. I have this: ENV["RAILS_ENV"] = "test" require File.expand_path(File.dirname(__FILE__) + "/../config/environment") require "ruby-debug" gem 'test-unit' require "test/unit" require 'active_support' require 'active_support/test_case' require 'active_record' require 'a...

"Joe Smith" is not the same as Joe Smith in rspec?

Hey, I'm using TDD with rails for the first time... interesting concepts. Definitely useful. That is, until I come to this. When I run my test I get: 1) User should build the full name correctly Failure/Error: @u1.fullname.to_s.should be("#{@attr[:firstname]} #{@attr[:lastname]}") expected Joe Smith, got "Joe Smith" # ./spec...

MbUnit's row attribute in NUnit?

While reading an Asp.Net MVC code sample that used MbUnit as it's testing framework, I saw that it was possible to run a single test against multiple input possibilities by using a Row attribute, like so: [Test] [Row("test@test_test.com")] [Row("sdfdf dsfsdf")] [Row("[email protected]")] public void Invalid_Emails_Should_Return_False(string in...

Unit-Testing Acceptance-Tests?

I am currently making some Acceptance-Tests that will help drive the design of a program I am about to do. Everything seems fine except I've realized that the Acceptance-Tests are kinda complex, that is, although they are conceptually simple, they require quite a bit of tricky code to run. I'll need to make a couple of "helper" classes f...

Should I use mocking for the following example

Hello, I am relatively new to using TDD and have been reading about mocking objects lately. I have the following test to test a method that given a date returns the next saturday. [TestMethod()] public void NextSaturdayTest() { DateTime date = new DateTime(); date = DateTime.Parse("2010-08-14"...