Book Review: Mockito Essentials by Sujoy Acharya
Mockito essentials is a straightforward insight towards writing proper form of unit tests using mockito framework. Targeted at existing developers, this book goes beyond the documented library and explains the method of correctly writing unit tests and its corresponding code.
The book starts by introducing test doubles, or assumptions that we make while writing unit tests which is essentially done through mockito, effectively laying the foundation of the book. Two subsequent chapters are devoted to the innards of the framework - which is very handy if you have mockito's programming reference ready.
However, the main problem of unit test lies in its implementation as real world code is generally not testable and often is unchangeable. Using mockito under BDD tests is also worth mentioning as this concept is not covered elsewhere till now. The book concludes with implementation of mockito based tests over webservices and rich client applications.
Overall, the book not only covers the mockito framework but also covers practical advice regarding testing existing code and making both legacy and new code testable and I'd highly recommend this book if you are looking to write unit tests in java applications.
Disclaimer: I received a copy of this book from packt publication before doing a review.
Access the book here:
http://bit.ly/1IoUXzo
Musings on computers and software as I continue learning and sharing software development knowledge.
Showing posts with label testing. Show all posts
Showing posts with label testing. Show all posts
Tuesday, January 27, 2015
Tuesday, December 30, 2014
Book Review: Learning Python Testing by Daniel Arbuckle
This is a review of Learning Python Testing by Daniel Arbuckle which as its name suggests, delves into testing with python. The testing frameworks covered are already covered in comprehensive python texts but instead of only high level overview, this textbook covers various testing frameworks and approaches in detailed manner.
The first chapter covers various forms of testing - something which could be covered in few subtopics and test driven development could have been discussed in greater detail. It then moves into doctest, which is unique approach in python and was discussed in depth - I've only known it vaguely before and the provided details opened up a sea of possibilities for me. For instance, the AVL tree example provided an excellent demonstration of doctest and is worth quoting. The next chapter provided unit tests with doctest and correctly explained the essence of unit testing. The PID controller example however was confusing and it took me frequently eyeballing the code - the logic used was complicated and consequently the test cases were larger. Next, mock objects were detailed - which are not present in other python texts. unittest.mock library in python3 was explained in depth before covering the details of this module. In the next chapter, the Nose test runner was discussed and its various customizations were also explained.
Test Driven Development was introduced relatively late in the book after all the testing frameworks were covered and covered writing specification and tests before code. For someone new to TDD philosophy, this book offers excellent introduction and covers all its facets and challenging the reader to do more - which I found as a pleasant surprise. This was followed by integration and system testing doctrine. The final chapter covering importance of testing in code coverage, version control and continuous integration wrapped up this handy textbook sufficiently.
Apart from some places where I found the text opinionated with the example taken, I enjoyed the rest of the book and specially places where the reader is asked to get off reading and try things to test his/her knowledge of the topic.
Disclaimer: I received a copy of this book[http://bit.ly/1HKQaIj] for doing its review.
The first chapter covers various forms of testing - something which could be covered in few subtopics and test driven development could have been discussed in greater detail. It then moves into doctest, which is unique approach in python and was discussed in depth - I've only known it vaguely before and the provided details opened up a sea of possibilities for me. For instance, the AVL tree example provided an excellent demonstration of doctest and is worth quoting. The next chapter provided unit tests with doctest and correctly explained the essence of unit testing. The PID controller example however was confusing and it took me frequently eyeballing the code - the logic used was complicated and consequently the test cases were larger. Next, mock objects were detailed - which are not present in other python texts. unittest.mock library in python3 was explained in depth before covering the details of this module. In the next chapter, the Nose test runner was discussed and its various customizations were also explained.
Test Driven Development was introduced relatively late in the book after all the testing frameworks were covered and covered writing specification and tests before code. For someone new to TDD philosophy, this book offers excellent introduction and covers all its facets and challenging the reader to do more - which I found as a pleasant surprise. This was followed by integration and system testing doctrine. The final chapter covering importance of testing in code coverage, version control and continuous integration wrapped up this handy textbook sufficiently.
Apart from some places where I found the text opinionated with the example taken, I enjoyed the rest of the book and specially places where the reader is asked to get off reading and try things to test his/her knowledge of the topic.
Disclaimer: I received a copy of this book[http://bit.ly/1HKQaIj] for doing its review.
Wednesday, October 31, 2012
An insight into sonar plugin development
In the recent months, I've been involved in developing a language plugin for sonar that displays different metrics for a specified language. I am writing this post as there is not much content available for this topic even when sonar is a widely popular tool.
Below are tips to avoid some of the common pitfalls in developing sonar:
- Read the official documentation carefully, even when there isn't much of it.
- Download the sources of all the open source plugins and try looking their code for proper understanding into plugin development.
- Do read books available on the topic in addition to the blogs for proper understanding.
- Use maven, this is a real lifesaver and focus on TDD while coding - as you cannot hope to debug the process otherwise.
If you've followed these steps diligently, you'd have a basic understanding on the innards of sonar plugin development.
In very brief words, a sonar plugin comprises of a java based program that performs the heavy duty work of loading/populating the code metrics and a ruby based UI (embedded ruby pages(erb)) that helps in displaying of this data, in a nice manner and also uses view helpers to create eye-catching widgets that display these data. There is another provision for a complete rails based application to be created in place of this, but that's a different idea altogether.
In my case, I needed to Populate the data from a database , so in a class implementing Sensor interface, following method was present
public void analyse(Project project, SensorContext sensorContext)
Inside this method, I can use Project object to read from project properties,etc as inputs to my process and SensorContext object as output in the form of measures;
sensorContext.saveMeasure(new Measure(MyMetricAnalysisClass.MetricName, Double.valueOf(metricVal)));
One of the nice features of working with erb templates in the UI for widgets is that you can use a lot of helper methods to create slick effects with your data. One such example is a piechart:
<%= piechart( 'Field1 = '+var1.to_s+'; Field2 = '+var2.to_s+';' , { :size => "500x200"}) -%>
One caveat present while transferring the data from server to views is that only text data works well, the information about using data structures is sketchy at best so we are left with using the data delimimted with ';' (See the first argument in piechart helper method above). Surprisingly, other data cause widgets to fail with no descriptive error messages. For larger data, it is more intuitive to use a GWT page instead of a widget as the users can focus more on the details provided in the page as opposed to the concise totals present on the widgets.
Hope this post helps the users developing plugins on this platform something to get started with.
Labels:
code quality,
development,
error,
java,
metrics,
sonar,
sonar plugin,
testing
Subscribe to:
Posts (Atom)
