- Java 9 Programming By Example
- Peter Verhas
- 321字
- 2021-07-02 23:37:38
Good unit tests
Is this a good unit test? If you read it in a tutorial book like this, it has to be. Actually, it is not. It is a good code to demonstrate some of the tools that JUnit provides and some Java language features, but as a real JUnit test, I will not use it in a real life project.
What makes a unit test good? To answer this question, we will have to find what the unit test is good for and what it is that we use it for.
We will create unit tests to validate the operation of the units and to document.
Unit tests are not to find bugs. Developers eventually use unit tests during debugging sessions but, many times, the testing code created for the debugging is a temporary one. When the bug is fixed, the code used to find it will not get into the source code. For every new bug, there should be a new test created that covers the functionality that was not properly working, but it is hardly the test code that is used to find the bug. This is because unit tests are mainly for documentation. You can document a class using JavaDoc, but the experience shows that the documentation often becomes outdated. The developers modify the code, but they do not modify the documentation, and the documentation becomes obsolete and misleading. Unit tests, however, are executed by the build system and if Continuous Integration (CI) is in use (and it should be, in a professional environment), then the build will be broken if a test fails, all developers will get mail notification about it, and it will drive the developer breaking the build to fix the code or the test. This way, the tests verify that continuous development did not break anything in the code or, at least, not something that can be discovered using unit tests.
- Learning Microsoft Windows Server 2012 Dynamic Access Control
- Getting Started with Citrix XenApp? 7.6
- Dynamics 365 for Finance and Operations Development Cookbook(Fourth Edition)
- 劍指JVM:虛擬機(jī)實(shí)踐與性能調(diào)優(yōu)
- PHP 編程從入門到實(shí)踐
- C++ 從入門到項(xiàng)目實(shí)踐(超值版)
- 高級(jí)語言程序設(shè)計(jì)(C語言版):基于計(jì)算思維能力培養(yǎng)
- Visual Basic程序設(shè)計(jì)
- 執(zhí)劍而舞:用代碼創(chuàng)作藝術(shù)
- Python+Tableau數(shù)據(jù)可視化之美
- Mastering C++ Multithreading
- 零基礎(chǔ)學(xué)C語言程序設(shè)計(jì)
- Java圖像處理:基于OpenCV與JVM
- 深入實(shí)踐DDD:以DSL驅(qū)動(dòng)復(fù)雜軟件開發(fā)
- 30天學(xué)通C#項(xiàng)目案例開發(fā)