MasterMastic
MasterMastic

Reputation: 21286

How to test the environment in TDD?

As I continue to learn and apply TDD I reach some points where I don't know how I could test before writing code (as I should).
It's with anything that's outside my application such as testing that:

How do I test these kind of things?

EDIT:
I'd like to focus on the first example, since I'm working on an application that actually requires those tests. How can I test the changing of a file?

Upvotes: 0

Views: 56

Answers (2)

John Saunders
John Saunders

Reputation: 161773

Any test which depends on the environment is not a unit test - it's an integration test. TDD does not apply to these.

You can, of course, create integration tests, and you can, or course, write those tests before you write the code that they test.

Upvotes: 1

dajohnson89
dajohnson89

Reputation: 79

Consider writing integration tests. Different from unit tests, which test isolated pieces of logic, integration tests function to make sure all of the pieces can properly communicate with each other.

Your integration test will reference property files, start up & shut down your service, and generally ensure none of your moving parts have been broken.

Sometimes, it is wise to mock the components. After all, you're not really testing the components, but the environment in which they operate.

Upvotes: 1

Related Questions