Skip to content

Let's Build Stuff and Test - Part 1

Recently, I wrote about the importance of tests in code and I want to demonstrate my way of working that makes it possible to test small chunks of code. This isn't going to be a definite how to guide on writing tests, but instead be more about knowledge sharing and inspiration for writing tests.

Now before any code is to be written, let's look at and analyze what is going to be built. To keep the domain simple enough to follow, but complex enough to show off the strengths of testing, I will be creating a simple invoice service that generates invoices for my customers. I will implement this in PHP because I enjoy a challenge in writing beautiful code in a language that doesn't have as many nice features and syntactical sugar as say for example C#. And finally, normally there would be a "product owner" to define the domain (business rules), but I'll be playing both roles in this.

So let's define the domain of this invoice service (which most likely does not reflect real world scenarios). We will have invoices, and invoices will definitely contain a customer, and an itemized list of products, services, campaign offers, and so on. The invoice will calculate the total price and show the taxes that were applied. Then we have the customer, which will have a name, address, and phone number that is required. And finally, we will start with implementing the products that are being sold to the customers. In the future, we might have a service or offer that will need to be added to the invoice, so we will not hardcode the type of items being added to the invoice, instead using an interface since the invoice shouldn't be concerned with what is being added to it.

I think that is a good enough start of the domain model to get some interesting code being written. I will save that for the next time though as I would love to hear your feedback on this so far.

Comments

Display comments as Linear | Threaded

No comments

Add Comment

You can use [geshi lang=lang_name [,ln={y|n}]][/geshi] tags to embed source code snippets.
Enclosing asterisks marks text as bold (*word*), underscore are made via _word_.
Standard emoticons like :-) and ;-) are converted to images.
E-Mail addresses will not be displayed and will only be used for E-Mail notifications.

To prevent automated Bots from commentspamming, please enter the string you see in the image below in the appropriate input box. Your comment will only be submitted if the strings match. Please ensure that your browser supports and accepts cookies, or your comment cannot be verified correctly.
CAPTCHA

Form options

Submitted comments will be subject to moderation before being displayed.