Click here to Skip to main content
15,913,685 members

Welcome to the Lounge

   

For discussing anything related to a software developer's life but is not for programming questions. Got a programming question?

The Lounge is rated Safe For Work. If you're about to post something inappropriate for a shared office environment, then don't post it. No ads, no abuse, and no programming questions. Trolling, (political, climate, religious or whatever) will result in your account being removed.

 
AnswerRe: TDD vs. just being careful Pin
Marc Clifton9-Jun-14 12:25
mvaMarc Clifton9-Jun-14 12:25 
GeneralRe: TDD vs. just being careful Pin
_Maxxx_9-Jun-14 14:29
professional_Maxxx_9-Jun-14 14:29 
GeneralRe: TDD vs. just being careful Pin
Marc Clifton10-Jun-14 2:53
mvaMarc Clifton10-Jun-14 2:53 
GeneralRe: TDD vs. just being careful Pin
Super Lloyd9-Jun-14 17:49
Super Lloyd9-Jun-14 17:49 
GeneralRe: TDD vs. just being careful Pin
Marc Clifton10-Jun-14 2:56
mvaMarc Clifton10-Jun-14 2:56 
GeneralRe: TDD vs. just being careful Pin
PIEBALDconsult9-Jun-14 14:24
mvePIEBALDconsult9-Jun-14 14:24 
AnswerRe: TDD vs. just being careful Pin
_Maxxx_9-Jun-14 14:27
professional_Maxxx_9-Jun-14 14:27 
GeneralRe: TDD vs. just being careful Pin
Dan Neely10-Jun-14 2:54
Dan Neely10-Jun-14 2:54 
_Maxxx_ wrote:
IMHO, when starting a new project, using TDD can be useful over the life of the project. Adding tests to an existing project - place in the 'too-hard' basket and move on.


I have to disagree. Adding tests to codethulu makes it much easier to eventually dismantle the monster into something sane. I started seriously adding test coverage to a long standing code base about 2 years ago; have most of the non-UI code under test (need to work on that at some point; too much business logic in event handlers) and am finally unwinding a number of blunders from years ago that have been chronic pains ever since. Once I'm able to hop back to the 2nd app using the shared part of it I should be able to undo the worst of what's been left.

The trick is to start with high level integration ("smoke") tests not unit tests.

Something I recently wrote elsewhere on the subject of adding tests to old code:




If you're dealing with large amounts of legacy code that isn't currently under test, getting test coverage now instead of waiting for a hypothetical big rewrite in the future is the right move. Starting by writing unit tests is not.

Without automated testing, after making any changes to the code you need to do some manual end to end testing of the app to make sure it's working. Start by writing high level integration tests to replace that. If your app reads files in, validates them, processes the data in some fashion, and displays the results you want tests that capture all of that.

Ideally you'll either have data from a manual test plan or be able to get a sample of actual production data to use. If not, since the app's in production, in most cases it's doing what it should be, so just make up data that will hit all the high points and assume the output is correct for now. It's no worse than taking a small function, assuming it's doing what it's name or any comments suggest it should be doing, and writing tests assuming it's working correctly.

C#
IntegrationTestCase1()
{
    var input = ReadDataFile("path\to\test\data\case1in.ext");
    bool validInput = ValidateData(input);
    Assert.IsTrue(validInput);

    var processedData = ProcessData(input);
    Assert.AreEqual(0, processedData.Errors.Count);

    bool writeError = WriteFile(processedData, "temp\file.ext");
    Assert.IsFalse(writeError);

    bool filesAreEqual = CompareFiles("temp\file.ext", "path\to\test\data\case1out.ext");
    Assert.IsTrue(filesAreEqual);
}


Once you've got enough of these high level tests written to capture the apps normal operation and most common error cases the amount of time you'll need to spend pounding on the keyboard to try and catch errors from the code doing something other than what you thought it was supposed to do will go down significantly making future refactoring (or even a big rewrite) much easier.

As you're able to expand unit test coverage you can pare down or even retire most of the integration tests. If your app's reading/writing files or accessing a DB, testing those parts in isolation and either mocking them out or having your tests begin by creating the data structures read from the file/database are an obvious place to start. Actually creating that testing infrastructure will take a lot longer than writing a set of quick and dirty tests; and every time you run a 2 minute set of integration tests instead of spending 30 minutes manually testing a fraction of what the integration tests covered you're already making a big win.
Did you ever see history portrayed as an old man with a wise brow and pulseless heart, waging all things in the balance of reason?
Is not rather the genius of history like an eternal, imploring maiden, full of fire, with a burning heart and flaming soul, humanly warm and humanly beautiful?
--Zachris Topelius

Training a telescope on one’s own belly button will only reveal lint. You like that? You go right on staring at it. I prefer looking at galaxies.
-- Sarah Hoyt

GeneralRe: TDD vs. just being careful Pin
Mat Fergusson10-Jun-14 11:05
Mat Fergusson10-Jun-14 11:05 
GeneralRe: TDD vs. just being careful Pin
Dan Neely10-Jun-14 11:11
Dan Neely10-Jun-14 11:11 
GeneralRe: TDD vs. just being careful Pin
Mat Fergusson10-Jun-14 11:12
Mat Fergusson10-Jun-14 11:12 
AnswerRe: TDD vs. just being careful Pin
Super Lloyd9-Jun-14 16:41
Super Lloyd9-Jun-14 16:41 
AnswerRe: TDD vs. just being careful Pin
BobJanova10-Jun-14 0:15
BobJanova10-Jun-14 0:15 
AnswerRe: TDD vs. just being careful Pin
Andy Brummer10-Jun-14 0:36
sitebuilderAndy Brummer10-Jun-14 0:36 
NewsGreat moment for AI! Pin
ridoy9-Jun-14 10:04
professionalridoy9-Jun-14 10:04 
GeneralRe: Great moment for AI! Pin
Kenneth Haugland9-Jun-14 10:14
mvaKenneth Haugland9-Jun-14 10:14 
GeneralRe: Great moment for AI! Pin
PIEBALDconsult9-Jun-14 10:14
mvePIEBALDconsult9-Jun-14 10:14 
GeneralRe: Great moment for AI! PinPopular
Pete O'Hanlon9-Jun-14 10:17
mvePete O'Hanlon9-Jun-14 10:17 
GeneralRe: Great moment for AI! Pin
Kenneth Haugland9-Jun-14 10:22
mvaKenneth Haugland9-Jun-14 10:22 
GeneralRe: Great moment for AI! Pin
Kornfeld Eliyahu Peter9-Jun-14 10:25
professionalKornfeld Eliyahu Peter9-Jun-14 10:25 
GeneralRe: Great moment for AI! Pin
Pete O'Hanlon9-Jun-14 10:31
mvePete O'Hanlon9-Jun-14 10:31 
GeneralRe: Great moment for AI! Pin
Kornfeld Eliyahu Peter9-Jun-14 10:37
professionalKornfeld Eliyahu Peter9-Jun-14 10:37 
GeneralRe: Great moment for AI! Pin
Mike Hankey9-Jun-14 10:31
mveMike Hankey9-Jun-14 10:31 
GeneralRe: Great moment for AI! Pin
Kornfeld Eliyahu Peter9-Jun-14 10:35
professionalKornfeld Eliyahu Peter9-Jun-14 10:35 
GeneralRe: Great moment for AI! Pin
Mike Hankey9-Jun-14 10:37
mveMike Hankey9-Jun-14 10:37 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.