Q:

Developing a whole application (not a single class) with TDD (BDD)?

After a lot of reading, learning examples and making simple class tests I desided to create my first simple real-life application using TDD.
My application should have the following behavior:

it's a console application with no user interface
it will download a Json (which represents an array) from some URL
extract some data from this array
download another Jsons using data from the first step
pass all this data in a file in a specified format.

Actually this application pulls a list of regions and cities from some website.
I able to perform refactoring, know what is low coupling, etc. but after several attempts I realize that I completely don't know an idea on how to design a whole application with TDD.
What are my first steps to build this particular application using TDD?  What is the base which will grow into the complete application?
I'm using PHP but this doesn't matter as I don't need code examples. Just an idea and, ideally, how this idea could be embodied in my particular case. What are the concrete first tests I should implement? Why?
I think there are a lot of people would love to know an answer. Thank you very much TDD guys!

A:

Test Driven Design starts with a test plan. The first cut of the test plan doesn't involve code in any way; it only looks at determining what a successful solution looks like. From your example: Invoking the application will create a file that has the following information in it ...
The next cut of your test plan looks at the resulting file in a lot more detail. How do you test that the content of the file is well-formed and is valid? How do you verify the content of the file? For instance, well-formed XML files can be passed through an XML parser of any kind without an error report. Valid XML files can be validated against a schema. To this point, you don't need to write any code. Create the XML schema, and create test files that are well-formed and also test files that are valid against the schema. Your testing process will only look at the result.
The next cut involves generating the output file. Your first piece of code consists of some test harness (to feed test data in) and the file generator. You can add some correctness tests now. For instance, create examplar output files and compare the files-under-test against the exemplars. diff and cmp are your friends here, but you may need to get a little creative if the XML formatting gets in the way.
Keep moving backwards on your input chain. Create JSON files that correspond to the test data from the previous step. Verify the well-formedness and validity of the JSON files using appropriate off-the-shelf tools. Again, use your test harness to match up a JSON file to the desired data to the desired output file. The code you create/deploy here is the JSON parser.
Similar step for the next stage. Start by using curl or wget to fetch the JSON file and feed this into your test harness. Again no code is required, just a pipeline of commands. You will have to construct by hand the exemplars for correctness testing, but the well-formedness and validity testing remain the same.
Finally, your application embeds the curl functionality and you have end-to-end testing already in place.

