Book Review Pragmatic Unit Testing in Java with Junit
Look at this book is just a Java project, just apply the contents of the book to the project. The author of this book is Andy Hunt and Dave Thomas. It is from their hands from "The Pragmatic Programmer". This "Pragmatic Unit Testing in Java with Junit" is the second book in the Pragmatic Starter Kit series. According to the author's statement, this series tells some basic practices that all software development is essential. The first one of this series is "pragmatic version control", telling version control, mainly introducing CVS, second primary lecture unit test, and third primary explanation automation (yet published). Writing is very refined, only more than 160 pages, because I have seen "Junit In Action" before, this book is just selective. I don't know if there is any write unit test when writing the program. Anyway, I didn't read this book. The consequence is that a lot of time is spent on debugging. The maximum feeling of writing unit test has the following: 1. I am very relieved to my code. Sleeping is more stable than before; 2. Stress time is very small, with my personal experience, our project is a small payment Project, I am responsible for the analysis of the CMPP protocol, the project has been conducted, this module has been basically completed, I add up less than 24 hours, especially the JUnit and Log4j, run the test case ( When you have a mistake, you can locate the wrong output, soon you can locate the error; 3. Programming is greatly enhanced, especially the test-driven development, this method is tested Development, require the test case, and then implement the test class based on the test case. The advantage of this method is that the test code is the customer of the test object, so when writing test code, ask you how to define the test object. The interface, but this method requires your test case to comprehensively, and this requires experience. Let's talk about this book, and the book is divided into 9 chapters and 4 appendices. The necessity, method and test drive of unit tests are all told. The second chapter introduces the unit test with a simple example. The third chapter introduces the use of the JUnit this unit test tool. Chapter 45 is the key points of this book. The fourth chapter introduces what should be tested. What should be tested, Chapter 5 Introduce how the boundary conditions should be tested, and the sixth chapter describes how to test with Mock Objects. What is MOCK OBJECTS? Simply put, it is a patterned object, which has the same interface as the object being accepted. For example, we want to test Class A, Class A to call the Class B function, but if Class B has not been implemented, then we can abstract an interface interfaceb from the interface of Class B, and build a class Class Mockb to implement This interface, general MOCKB's implementation is very simple, its existence is just to facilitate testing Class A. It is important to note that we have to test Class A, not Class Mockb Mock Object. A very common misunderstanding of Mock Objects is now the test case has become a test Mock Objects. Regarding the use of Mock Objects, there is also a chapter written in "Junit In Action".