Introduction to Testing in Java Published


A brief outline of my first course on Pluralsight

Thu 13 August 2015

A couple of months ago I published my first Pluralsight course, Introduction to Testing in Java. A big motivation behind writing this course was trying to help the large group of people who would like to write tests for their code but are not sure where to begin. I would also like to help developers who do write tests but are never satisfied that the tests are easy to maintain or read.

I enjoyed course - it is very hands-on and drive every point to a conclusion while providing great insight. - Sina Jazayeri

I have been running in-person training courses with my friend Raoul on Java 8 for about a year or so now which are good fun to run. We often have great attendees who ask interesting questions and spawn some good discussion. Having said that teaching people in person can be a little bit limiting - you need to travel around a lot and it only makes sense if there are enough people in one place to want to take the course. Selling online courses allows you to much more easily help a much wider audience learn.

Testing is one of those topics which can feel like a bit of burden when you get started. I know my first attitude towards automated testing was pretty arrogant - I'm a developer, not someone who writes tests for a living! Over time though I found that by having a strong automated regression suite it's very easy to ensure that you are not building your house on crumbling foundations. This course starts off by explaining why you might want to write tests for your code to begin with.

As it's designed to help even the most junior of developer, this course doesn't assume that you know anything about testing or JUnit and explains how you write your first test. If you are a more experienced developer then you might be able to just skip straight over the opening couple of modules.

I never used JUnit due to lot of doubts on it, and I was afraid to try it. With this course now I want to code something just for start to use JUnit. - aescamilla

I've also found a problem that many people struggle with when writing test code is a refusal to treat it like "real" code. In other words they cut corners or don't apply the same quality of refactoring that they would to production code. My view is that this is a pretty big mistake. You've got to maintain your test code - it does have a maintenance burden and the same approaches of reducing duplication and trying to keep the code clean are a benefit. In the course I both cover the duplication and refactoring of tests and also discuss some code quality issues that are specifically related to testing. Specifically tests which have bad diagnostics around failures or which test the implementation of a class and not its externally observable behaviour.

tests are talked about and refactored with the same respect as the development code. - Jay Gehlot

Even after I had sold myself on writing automated tests it still took me a while before I got used to the idea of TDD - Test Driven Development. This is the practice of writing your tests before anything implements them and only writing the simplest code that makes them pass. I also cover the basics of TDD in this pluralsight course explaining how you build out algorithms step by step using triangulation. These days I don't TDD everything I write, but there are definitely some pieces of code which are absolutely ideal for developing test first and letting tests drive their implementation and design.

A lot of real world Java applications are not particularly heavy in the algorithmic department of course. Whilst the classical style of TDD outlined above is great for algorithmic work it doesn't perform so well when helping us flesh out cleanly decoupled classes and their interactions and responsibilities. The last two modules of the course cover that kind of testing by explaining the dependency relationship between two classes and how we can write isolated tests for classes with dependencies using mocks and stubs.

The course is good and the concepts are clearly explained. - Chemeware

By now you have probably stopped reading this blog post and headed on over to the pluralsight course page but if not I will just add that I have also released a second course about Java Generics on Pluralsight and am looking forward to doing more work on there.

Thanks to James Ross, Trisha Gee and Matthew Cranman for proof reading this blog post.