The art of automate tests__ writing code of building maintainable Software-java Chapter

Source: Internet
Author: User
automate Tests of building maintainable Software-java Chapter

Keep the bar Green to Keep of the code clean.
-the JUnit Motto

guideline:Automate TestsFor your codebase.
do this by writing automated tests using a test framework.
this improves maintainability because automated testing makes development predictable and less risky.

Motivation automated testing makes testing repeatableJust like other programs and scripts, automated tests are executed in exactly the same
Way every time they are run. This makes testing repeatable:if a certain test executes at
Two different points in time yet gives different, it answers is that the test cannot execution is itself. One can conclude that something has changed in the system
That has caused the different outcome. With manual tests, there is always the possibility this tests are not performed consistently or that human errors are .

automated testing makes Development efficient
Automated tests can be executed with much less effort than manual. The effort
They require is negligible and can repeated as often as for you. They are also
Faster than manual code review. You are should also test as early in the development process as possible, to limit the effort it takes to fix problems.


automated testing makes Code predictable

Technical tests can be automated to a high degree. Take unit tests and integration
Tests:they test the technical inner workings of code and the cohesion/integration of
That code. Without being sure of the inner workings of your system, you might get
The right results by accident. It is a bit like driving a car:you might arrive at a
Intended destination by following the wrong directions, but if you are want to go
Another destination, you are uncertain whether the new directions are and
Would actually take you there.
A common advantage of automated testing is identifying then regression is occur‐
Ring. Without a batch of automated unit tests, development quickly to turns into a game
of whack-a-mole:you implement a change in one piece's code, and while you are
Working on the next change in another piece of code, for you realize you have introduced
A bug with your previous change. Automated tests allow to double-check your
Entire codebase effortlessly before turning to the next change. And since the automa‐
Ted unit tests follow predefined paths, you can be sure this if you have fixed a bug, it
does not pops up on a second run.


Thus, running automated tests provides certainty about how the code works. There‐
Fore, the predictability of automated tests also makes the quality of developed code
More predictable.


Tests Document The Code this is testedThe script or program code of a test contains assertions about the expected
Behavior of the system under test.


writing Tests make your Write Better CodeWriting tests helps to write testable code. As a side effect, this leads to code consisting of units that are shorter, are simpler, have fewer parameters, and are mor E loosely coupled (as the guidelines in the previous chapters advise).


How to Apply the guideline

How do you automate tests differs by the types of tests your want to automate. Test types
differ in what are tested, by whom, and why, as detailed in Table 10-1. They are ordered
From top to bottom based on the scope of the tests. For example, a unit test has the
Unit as scope, while the End-to-end test, a regression test, and an acceptance test are
On the system level.




Table 10-1 shows that a regression test was a unit test, a integration test, or a end-toend test that has been created En a bug was fixed. Acceptance tests are end-to-end tests by the end user executed.
Different types of testing call for different automation frameworks. For the unit testing,
Several well-known Java frameworks are available, such as JUnit. For automated
End-to-end testing, you need a framework that can mimic user input and capture
Output. A well-known framework that does just the for web development is sele‐
Nium. For integration testing, it all depends on the environment in which to you are
Working and the quality characteristics you are testing. SOAPUI is a framework for
Integration tests that focuses on Web services and messaging middleware. Apache
JMeter is a framework for testing the performance of Java applications under heavy
Workloads.
Choosing a test framework needs to is done in the team level. Writing integration
Tests is a specialized skill-but the unit testing be for each and every individual.
That's why the rest of this chapter focuses to writing unit tests using the most framework for wellknown.


Getting Started with JUnit Tests

General principles to writing good unit Tests

When writing tests, it's important to keep in mind the following general principles:


Test both normal and special cases


Maintain tests just like nontest (production) code


Write tests that are isolated:their outcomes should rešect only the behavior of the subject being




Coverage to determine Whether There Are enough Tests Measure

Reading notes: Building maintainable Software:ten guidelines for Future-proof Code
by Joost Visser
copyright©2016 Software Improvement Group, B.V. All rights reserved.
Printed in the United States of America.
Published by O ' Reilly Media, Inc., 1005 Gravenstein Highway north, Sebastopol, CA 95472.
O ' Reilly books are purchased for educational, business, or sales promotional with use. Online editions are
Also available for most titles (http://safaribooksonline.com). For more information, contacts our corporate/
Institutional sales department:800-998-9938 or corporate@oreilly.com.
Acquisitions Editor:rachel Roumeliotis
Editor:nan Barber
Production Editor:matthew Hacker
Copyeditor:rachel Monaghan
Proofreader:marta Justak
Indexer:wordco Indexing Services, Inc.
Interior Designer:david Futato
Cover Designer:randy Comer
Illustrator:rebecca Demarest
February 2016:first Edition
Revision History for the A
2016-01-25:first Release
Http://shop.oreilly.com/product/0636920049159.do

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.