[Book Review] Unit testing of programming sites that can be done with zero experience

I've always wanted to read a test-related book, but I happened to find this book at a bookstore, so I bought it. Although I have many opportunities to do unit tests in the field, I haven't learned much about it, so I thought it was a good opportunity to read it.

http://www.shoeisha.co.jp/book/detail/9784798118918

[Composition and contents]

This book consists of three parts. There are detailed chapters in each part. I will write a brief explanation of each part (chapter) and the impressions and post-reading memos I felt in it.

** <Part 1 Unit tests cannot be underestimated> **

――Chapter 1: Why do you recommend unit tests for extremely busy sites? --Chapter 2: Get acquainted with unit testing of web applications

・ Part 1 gives an overview of unit tests under the theme of "Unit tests cannot be underestimated."   In Chapter 1, check the types and purposes of tests performed in system development. In addition to unit tests, we confirm that there are many tests such as integration tests, system tests / load tests, security tests, etc., and then explain that the quality of the unit tests performed first is important.

In addition, as a unit test implementation method, we recommend the method of "creating a test class and automatically executing / confirming it". (This book will continue in the form of explaining the unit test method for creating a test class in the following sections (chapter).)

↑↑ This document describes how to use JUnit to unit test Java programs.

Chapter 2 introduces the points to be noted when unit testing a Web application and the main methods of unit testing. The author recommends subdividing the test because "testing after making everything = time consuming", but for Web applications created with MVC, the range to be tested is reduced as follows. I recommend that you test it. (① → ②)

① First test Model (2) Test the web application (View / Model / Controller) on the web container

Regarding the unit test method, the white box test and black box test are briefly introduced, but since it does not describe how to make detailed test cases, I think that you should refer to books other than this book. Part 1 focuses on reviewing test perspectives in system development rather than specific unit testing methods. Personally, I thought that ** I would make the whole MVC and then unit test it **, so the perspective of ** being able to test in small pieces ** was a new discovery.

** <Part 2 High-value unit tests to be performed> **

--Chapter 3: Test class created with Eclipse and JUnit --Chapter 4: Unit test of DB access --Chapter 5: How to reduce DB access test cases --Chapter 6: Testing Business Logic and External Resource Access --Chapter 7: External system linkage and screen side test

・ The theme of Part 2 is "Unit tests with high value". The unit test of Java program is actually explained using a sample. (Eclipse + JUnit + DbUnit environment)   Chapter 3 is about creating and executing a test class using sample code. Introduces how to use JUnit4 annotations and methods for judging test results (assertXXX / fail, etc.). I was able to learn about the test class practically because I could actually run the source using the sample. It contains all the annotation methods required to create a test class, so I think it's a useful chapter as a textbook when building JUnit.

Chapters 4 and 5 are about testing DB access. I first learned about DBUnit in this book. I was impressed that it was very convenient to have a testing framework. There is also a lot of practical information such as how to use DBUnit and annotations. I haven't actually used it in the field yet, so I definitely want to take this opportunity to use it. Since it is used under the JUnit environment, it seems to be familiar. DBUnit is very convenient because you can back up the state before the test (@Before) and return the backup data to the DB (@After) after the test. (Tests can proceed efficiently!) Samples are also included in this chapter, so you can check the method while actually moving your hands.

Chapter 6. About Mock objects. I have never used this again. (I am keenly aware of lack of study ...) It is stated that in order to create a Mock object, it is necessary to understand the specifications in order to imitate the behavior. (On the other hand, if you create a Mock class, it is written that it is more efficient to create a real class and then test it.) I think it is worth reading as a method that you may use in the future. * Mock = pseudo.

Chapter 7 introduces how to get screen coverage. You can learn how to get coverage using a tool called EMMA. I had used EMMA in the field, so it was just right for reconfirmation.

In the second part, all the points that should be suppressed when testing in the Java field were introduced. As for the test method, I don't have a chance to study, so I would be very grateful if I had a book like this.

** <Part 3 For continuous testing> **

--Chapter 8: Be aware of testing before implementation ――Chapter 9: Points of development with test in mind ――Chapter 10: Points to further save labor in testing --Chapter 11: Building an environment that automates build and testing

・ The theme of Part 3 is to be aware of the test from the manufacturing stage in order to perform the test more efficiently. It also introduces how to build an environment for continuous testing by preparing a build server.

At the beginning of Chapter 8, we introduced the phrase "quality is created in the process". It emphasizes that it is a good test condition to consider the test from the stage of considering the software architecture and to have a common awareness within the project. Chapter 9 also states that it is important to design to reduce unnecessary tests while proceeding with development. Make the argument types meaningful, how to test methods that handle system dates, etc. It also introduces how to use static tools such as CheckStyle and FindBugs as bug finding tools. Chapter 10 and subsequent chapters are about creating an environment for improving test efficiency and automation.

[Impression] ・ I usually work as a Java engineer, but there were many tools I didn't know until I read this book, so it was very helpful. Until now, I have only vaguely tested, but I would like to practice effective testing to improve the quality. This book is easy to read even for beginners, so if you are not good at testing, please read it.

Recommended Posts

[Book Review] Unit testing of programming sites that can be done with zero experience
[Book Review] Unit test of programming site that can be done with zero experience (sequel 1-JUnit ~)
Summary of css selectors that can be used with Nookogiri
Summary of JDK that can be installed with Homebrew (as of November 2019)
Organize methods that can be used with StringUtils
[Ruby] Methods that can be used with strings
"Inheritance" that even beginners of object-oriented programming can understand
Polymorphism that even beginners of object-oriented programming can understand
The world of Azure IoT that can be played on the DE10-Nano board: Ajuchika with FPGA !!?