A BSG Java Developer hosted a live coding demonstration at JoziJUG on Monday, 23 February 2015. The purpose of the demonstration was to show an alternate way of writing tests, one that allows for more succinct and easy-to-read tests to be created, which is designed to avoid repetition and emphasise the intention of the tests whenever the results are checked by comparing the actual values of attributes on an object with what was expected.
When asked to comment on his approach, the developer had this to say, “Often the results of a method under test are verified by checking the state of the returned object. This quickly becomes cumbersome if there are even just a handful of fields to check, and more so if you have multiple tests checking the same fields. During the live coding I explored how using matchers can make your tests much more succinct and readable. I demonstrated how to write custom Hamcrest matchers, using Shazamcrest, and briefly demonstrated how to use argument matchers to check the state of arguments being passed to mock collaborators.”
As a niche consulting and technology company with expertise in both business consulting and software development, BSG is committed to ensuring its employees are on the cutting edge of their respective industries. With Java and .Net developers working in agile development environments across its client base, BSG ensures its developers are equipped with the best technology and are exposed to the highest level of thought leadership in the industry. For more on BSG’s development focus, click here.