100% found this document useful (6 votes)
2K views

Python Continuous Integration and Delivery: A Concise Guide With Examples Lenz 2024 Scribd Download

Lenz

Uploaded by

safoyapharoe29
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
100% found this document useful (6 votes)
2K views

Python Continuous Integration and Delivery: A Concise Guide With Examples Lenz 2024 Scribd Download

Lenz

Uploaded by

safoyapharoe29
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 52

Download the full version of the textbook now at textbookfull.

com

Python Continuous Integration and Delivery: A


Concise Guide with Examples Lenz

https://textbookfull.com/product/python-
continuous-integration-and-delivery-a-concise-
guide-with-examples-lenz/

Explore and download more textbook at https://textbookfull.com


Recommended digital products (PDF, EPUB, MOBI) that
you can download immediately if you are interested.

Perl 6 Fundamentals: A Primer with Examples, Projects, and


Case Studies Moritz Lenz

https://textbookfull.com/product/perl-6-fundamentals-a-primer-with-
examples-projects-and-case-studies-moritz-lenz/

textbookfull.com

Xamarin Continuous Integration and Delivery: Team


Services, Test Cloud, and HockeyApp 1st Edition Gerald
Versluis (Auth.)
https://textbookfull.com/product/xamarin-continuous-integration-and-
delivery-team-services-test-cloud-and-hockeyapp-1st-edition-gerald-
versluis-auth/
textbookfull.com

Online Machine Learning: A Practical Guide with Examples


in Python 1st Edition Thomas Bartz-Beielstein

https://textbookfull.com/product/online-machine-learning-a-practical-
guide-with-examples-in-python-1st-edition-thomas-bartz-beielstein/

textbookfull.com

Revisiting Shakespeare’s Lost Play: Cardenio/Double


Falsehood in the Eighteenth Century 1st Edition Deborah C.
Payne (Eds.)
https://textbookfull.com/product/revisiting-shakespeares-lost-play-
cardenio-double-falsehood-in-the-eighteenth-century-1st-edition-
deborah-c-payne-eds/
textbookfull.com
Feeling It Language Race and Affect in Latinx Youth
Learning Mary Bucholtz

https://textbookfull.com/product/feeling-it-language-race-and-affect-
in-latinx-youth-learning-mary-bucholtz/

textbookfull.com

Fighter's Fact Book 2 Street Fighting Essentials


Christensen Loren

https://textbookfull.com/product/fighters-fact-book-2-street-fighting-
essentials-christensen-loren/

textbookfull.com

The Datacenter As A Computer Designing Warehouse Scale


Machines Luiz André Barroso

https://textbookfull.com/product/the-datacenter-as-a-computer-
designing-warehouse-scale-machines-luiz-andre-barroso/

textbookfull.com

Transforming Perspectives in Lifelong Learning and Adult


Education: A Dialogue Laura Formenti

https://textbookfull.com/product/transforming-perspectives-in-
lifelong-learning-and-adult-education-a-dialogue-laura-formenti/

textbookfull.com

Essentials of Organizational Behavior: An Evidence-Based


Approach Teresa (Terri) A. (Anne) Scandura

https://textbookfull.com/product/essentials-of-organizational-
behavior-an-evidence-based-approach-teresa-terri-a-anne-scandura/

textbookfull.com
Towards a Maq■■id al-Shar■■ah Index of Socio-Economic
Development: Theory and Application Salman Syed Ali

https://textbookfull.com/product/towards-a-maqa%e1%b9%a3id-al-
shari%ca%bfah-index-of-socio-economic-development-theory-and-
application-salman-syed-ali/
textbookfull.com
Python
Continuous
Integration
and Delivery
A Concise Guide with Examples

Moritz Lenz
Python Continuous
Integration and
Delivery
A Concise Guide with Examples

Moritz Lenz
Python Continuous Integration and Delivery: A Concise Guide with
Examples
Moritz Lenz
Fürth, Bayern, Germany

ISBN-13 (pbk): 978-1-4842-4280-3 ISBN-13 (electronic): 978-1-4842-4281-0


https://doi.org/10.1007/978-1-4842-4281-0
Library of Congress Control Number: 2018967720

Copyright © 2019 by Moritz Lenz


This work is subject to copyright. All rights are reserved by the Publisher, whether the whole or
part of the material is concerned, specifically the rights of translation, reprinting, reuse of
illustrations, recitation, broadcasting, reproduction on microfilms or in any other physical way,
and transmission or information storage and retrieval, electronic adaptation, computer software,
or by similar or dissimilar methodology now known or hereafter developed.
Trademarked names, logos, and images may appear in this book. Rather than use a trademark
symbol with every occurrence of a trademarked name, logo, or image, we use the names, logos,
and images only in an editorial fashion and to the benefit of the trademark owner, with no
intention of infringement of the trademark.
The use in this publication of trade names, trademarks, service marks, and similar terms, even if
they are not identified as such, is not to be taken as an expression of opinion as to whether or not
they are subject to proprietary rights.
While the advice and information in this book are believed to be true and accurate at the date of
publication, neither the author nor the editors nor the publisher can accept any legal
responsibility for any errors or omissions that may be made. The publisher makes no warranty,
express or implied, with respect to the material contained herein.
Managing Director, Apress Media LLC: Welmoed Spahr
Acquisitions Editor: Steve Anglin
Development Editor: Matthew Moodie
Coordinating Editor: Mark Powers
Cover designed by eStudioCalamar
Cover image designed by Freepik (www.freepik.com)
Distributed to the book trade worldwide by Springer Science+Business Media New York, 233
Spring Street, 6th Floor, New York, NY 10013. Phone 1-800-SPRINGER, fax (201) 348-4505, e-mail
orders-ny@springer-sbm.com, or visit www.springeronline.com. Apress Media, LLC is a
California LLC and the sole member (owner) is Springer Science+Business Media Finance Inc
(SSBM Finance Inc). SSBM Finance Inc is a Delaware corporation.
For information on translations, please e-mail editorial@apress.com; for reprint, paperback, or
audio rights, please e-mail bookpermissions@springernature.com.
Apress titles may be purchased in bulk for academic, corporate, or promotional use. eBook
versions and licenses are also available for most titles. For more information, reference our Print
and eBook Bulk Sales web page at www.apress.com/bulk-sales.
Any source code or other supplementary material referenced by the author in this book is
available to readers on GitHub via the book’s product page, located at www.apress.com/
9781484242803. For more detailed information, please visit www.apress.com/source-code.
Printed on acid-free paper
Table of Contents
About the Author���������������������������������������������������������������������������������xi
About the Technical Reviewer�����������������������������������������������������������xiii
Acknowledgments������������������������������������������������������������������������������xv
Introduction��������������������������������������������������������������������������������������xvii

Chapter 1: Automated Testing��������������������������������������������������������������1


1.1 What Do We Want from a Test?����������������������������������������������������������������������1
Fast Feedback�������������������������������������������������������������������������������������������������1
Confidence�������������������������������������������������������������������������������������������������������2
Debugging Aid�������������������������������������������������������������������������������������������������3
Design Help�����������������������������������������������������������������������������������������������������3
Specification of the Product����������������������������������������������������������������������������4
1.2 Downsides of Tests����������������������������������������������������������������������������������������5
Effort����������������������������������������������������������������������������������������������������������������5
Extra Code to Maintain������������������������������������������������������������������������������������5
Brittleness�������������������������������������������������������������������������������������������������������6
False Sense of Security�����������������������������������������������������������������������������������6
1.3 Characteristics of a Good Test�����������������������������������������������������������������������7
1.4 Kinds of Tests�������������������������������������������������������������������������������������������������7
Unit Tests���������������������������������������������������������������������������������������������������������7
Integration Tests����������������������������������������������������������������������������������������������8
System Tests���������������������������������������������������������������������������������������������������9

iii
Table of Contents

Smoke Tests��������������������������������������������������������������������������������������������������10
Performance Tests�����������������������������������������������������������������������������������������10
1.5 Summary�����������������������������������������������������������������������������������������������������12

Chapter 2: Unit Testing in Python�������������������������������������������������������13


2.1 Digression: Virtualenvs��������������������������������������������������������������������������������14
2.2 Getting Started with Unit Tests��������������������������������������������������������������������15
The First Test�������������������������������������������������������������������������������������������������16
Writing More Tests�����������������������������������������������������������������������������������������17
Testing the Unhappy Path������������������������������������������������������������������������������19
2.3 Dealing with Dependencies�������������������������������������������������������������������������20
Separating Logic from External Dependencies���������������������������������������������21
Dependency Injection for Testing������������������������������������������������������������������24
Mock Objects�������������������������������������������������������������������������������������������������27
Patching��������������������������������������������������������������������������������������������������������28
2.4 Separating Code and Tests��������������������������������������������������������������������������30
Tweaking the Python Path�����������������������������������������������������������������������������31
2.5 More on Unit Testing and Pytest������������������������������������������������������������������32
2.6 Running Unit Tests in Fresh Environments��������������������������������������������������32
2.7 Another Sample Project: matheval���������������������������������������������������������������34
Application Logic�������������������������������������������������������������������������������������������34
2.8 Summary�����������������������������������������������������������������������������������������������������38

Chapter 3: Continuous Integration with Jenkins��������������������������������39


3.1 Continuous Integration Servers�������������������������������������������������������������������40
3.2 Getting Started with Jenkins�����������������������������������������������������������������������41
Run Jenkins in Docker�����������������������������������������������������������������������������������41
Configure a Source Code Repository�������������������������������������������������������������43
Creating the First Jenkins Job�����������������������������������������������������������������������43

iv
Table of Contents

3.3 Exporting More Test Details to Jenkins��������������������������������������������������������47


3.4 Patterns for Working with Jenkins���������������������������������������������������������������48
Responsibilities���������������������������������������������������������������������������������������������49
Notifications��������������������������������������������������������������������������������������������������49
Feature Branches and Pull Requests�������������������������������������������������������������50
3.5 Other Metrics in Jenkins������������������������������������������������������������������������������50
Code Coverage����������������������������������������������������������������������������������������������51
Complexity�����������������������������������������������������������������������������������������������������51
Coding Style��������������������������������������������������������������������������������������������������51
Architectural Constraint Checking�����������������������������������������������������������������52
3.6 Summary�����������������������������������������������������������������������������������������������������52

Chapter 4: Continuous Delivery����������������������������������������������������������53


4.1 Reasons for CD and Automated Deployments���������������������������������������������54
Time Savings�������������������������������������������������������������������������������������������������54
Shorter Release Cycles����������������������������������������������������������������������������������55
Shorter Feedback Cycles�������������������������������������������������������������������������������55
Reliability of Releases�����������������������������������������������������������������������������������56
Smaller Increments Make Triaging Easier�����������������������������������������������������57
More Architectural Freedom��������������������������������������������������������������������������57
Advanced Quality Assurance Techniques������������������������������������������������������58
4.2 A Plan for CD������������������������������������������������������������������������������������������������59
The Pipeline Architecture������������������������������������������������������������������������������59
Anti-Pattern: Separate Builds per Environment���������������������������������������������61
Everything Hinges on the Packaging Format������������������������������������������������62
Technology for Managing Debian Repositories���������������������������������������������63
Tooling for Installing Packages����������������������������������������������������������������������64
Controlling the Pipeline���������������������������������������������������������������������������������65
4.3 Summary�����������������������������������������������������������������������������������������������������66

v
Table of Contents

Chapter 5: Building Packages�������������������������������������������������������������67


5.1 Creating a Python Source Tarball�����������������������������������������������������������������67
5.2 Debian Packaging with dh-virtualenv����������������������������������������������������������68
Getting Started with Packaging���������������������������������������������������������������������69
5.3 The control File��������������������������������������������������������������������������������������������70
Directing the Build Process���������������������������������������������������������������������������70
Declaring Python Dependencies��������������������������������������������������������������������71
Building the Package�������������������������������������������������������������������������������������72
Creating the python-matheval Package��������������������������������������������������������72
Tradeoffs of dh-virtualenv�����������������������������������������������������������������������������74
5.4 Summary�����������������������������������������������������������������������������������������������������75

Chapter 6: Distributing Debian Packages�������������������������������������������77


6.1 Signatures����������������������������������������������������������������������������������������������������77
6.2 Preparing the Repository�����������������������������������������������������������������������������78
6.3 Automating Repository Creation and Package Addition�������������������������������80
6.4 Serving the Repositories������������������������������������������������������������������������������82
Configuring a Machine to Use the Repository�����������������������������������������������84
6.5 Summary�����������������������������������������������������������������������������������������������������85

Chapter 7: Package Deployment���������������������������������������������������������87


7.1 Ansible: A Primer������������������������������������������������������������������������������������������87
Connections and Inventory����������������������������������������������������������������������������88
Modules���������������������������������������������������������������������������������������������������������90
The shell Module�������������������������������������������������������������������������������������������90
The copy Module�������������������������������������������������������������������������������������������91
The template Module�������������������������������������������������������������������������������������92
The file Module����������������������������������������������������������������������������������������������93
The apt Module����������������������������������������������������������������������������������������������93

vi
Table of Contents

The yum and zypper Modules�����������������������������������������������������������������������94


The package Module�������������������������������������������������������������������������������������94
Application-Specific Modules������������������������������������������������������������������������95
Playbooks������������������������������������������������������������������������������������������������������95
Variables��������������������������������������������������������������������������������������������������������99
Roles������������������������������������������������������������������������������������������������������������101
7.2 Deploying with Ansible�������������������������������������������������������������������������������104
7.3 Summary���������������������������������������������������������������������������������������������������106

Chapter 8: A Virtual Playground for Automating Deployments��������107


8.1 Requirements and Resource Usage�����������������������������������������������������������107
8.2 Introducing Vagrant������������������������������������������������������������������������������������108
Network and Vagrant Setup�������������������������������������������������������������������������110
8.3 Configuring the Machines��������������������������������������������������������������������������113
8.4 Summary���������������������������������������������������������������������������������������������������121

Chapter 9: Building in the Pipeline with Go Continuous Delivery�����123


9.1 About Go Continuous Delivery��������������������������������������������������������������������123
Pipeline Organization�����������������������������������������������������������������������������������124
Matching of Jobs to Agents�������������������������������������������������������������������������125
A Word on Environments�����������������������������������������������������������������������������126
Materials������������������������������������������������������������������������������������������������������126
Artifacts�������������������������������������������������������������������������������������������������������127
9.2 Installation�������������������������������������������������������������������������������������������������127
Installing the GoCD Server on Debian����������������������������������������������������������127
Installing a GoCD Agent on Debian��������������������������������������������������������������129
First Contact with GoCD’s XML Configuration����������������������������������������������130
Creating an SSH Key������������������������������������������������������������������������������������132

vii
Table of Contents

9.3 Building in the Pipeline������������������������������������������������������������������������������132


Directory Layout������������������������������������������������������������������������������������������134
Stages, Jobs, Tasks, and Artifacts���������������������������������������������������������������134
The Pipeline in Action����������������������������������������������������������������������������������136
Version Recycling Considered Harmful�������������������������������������������������������137
Constructing Unique Version Numbers��������������������������������������������������������137
Other Bits and Pieces Around the Build�������������������������������������������������������139
Plugging It into GoCD�����������������������������������������������������������������������������������139
9.4 Summary���������������������������������������������������������������������������������������������������141

Chapter 10: D
 istributing and Deploying Packages in the Pipeline������143
10.1 Uploading in the Pipeline�������������������������������������������������������������������������143
User Accounts and Security�������������������������������������������������������������������������146
10.2 Deploying in the Pipeline�������������������������������������������������������������������������147
10.3 Results�����������������������������������������������������������������������������������������������������149
10.4 Going All the Way to Production���������������������������������������������������������������150
10.5 Achievement Unlocked: Basic Continuous Delivery���������������������������������152

Chapter 11: Pipeline Improvements�������������������������������������������������153


11.1 Rollbacks and Installing Specific Versions�����������������������������������������������153
Implementation�������������������������������������������������������������������������������������������154
Try It!�����������������������������������������������������������������������������������������������������������156
11.2 Running Smoke Tests in the Pipeline�������������������������������������������������������157
When to Smoke?�����������������������������������������������������������������������������������������157
White Box Smoke Testing����������������������������������������������������������������������������158
Sample Black Box Smoke Test��������������������������������������������������������������������158
Adding Smoke Tests to the Pipeline and Rolling Releases��������������������������159

viii
Table of Contents

11.3 Configuration Templates��������������������������������������������������������������������������161


11.4 Avoiding the Rebuild Stampede���������������������������������������������������������������164
11.5 Summary�������������������������������������������������������������������������������������������������166

Chapter 12: Security�������������������������������������������������������������������������167


12.1 The Dangers of Centralization������������������������������������������������������������������167
12.2 Time to Market for Security Fixes������������������������������������������������������������169
12.3 Audits and Software Bill of Materials�������������������������������������������������������169
12.4 Summary�������������������������������������������������������������������������������������������������170

Chapter 13: State Management��������������������������������������������������������171


13.1 Synchronization Between Code and Database Versions��������������������������172
13.2 Decoupling Application and Database Versions���������������������������������������173
Example of a Schema Change���������������������������������������������������������������������174
Prerequisites�����������������������������������������������������������������������������������������������179
Tooling���������������������������������������������������������������������������������������������������������180
Structure������������������������������������������������������������������������������������������������������180
No Silver Bullet��������������������������������������������������������������������������������������������181
13.3 Summary�������������������������������������������������������������������������������������������������181

Chapter 14: Conclusions and Outlook�����������������������������������������������183


14.1 What’s Next?��������������������������������������������������������������������������������������������183
Improved Quality Assurance������������������������������������������������������������������������183
Metrics��������������������������������������������������������������������������������������������������������184
Infrastructure Automation���������������������������������������������������������������������������185
14.2 Conclusions����������������������������������������������������������������������������������������������187

Index�������������������������������������������������������������������������������������������������189

ix
Visit https://textbookfull.com
now to explore a rich
collection of eBooks, textbook
and enjoy exciting offers!
About the Author
Moritz Lenz is a prolific blogger, author, and
contributor to Open Source projects.
He works as software architect and
principal software engineer for a midsize IT
outsourcing company, where he has created a
Continuous Integration and Delivery system
for over 50 software libraries and applications.

xi
About the Technical Reviewer
Michael Thomas has worked in software
development for over 20 years as an individual
contributor, team lead, program manager,
and vice president of engineering. Michael
has more than 10 years of experience working
with mobile devices. His current focus is in
the medical sector, using mobile devices
to accelerate information transfer between
patients and health-­care providers.

xiii
Acknowledgments
Writing a book is not a solitary endeavor and is only possible with help
from many individuals and organizations. I would like to thank all of my
beta readers who provided feedback. These include, in no particular order,
Karl Vogel, Mikhail Itkin, Carl Mäsak, Martin Thurn, Shlomi Fish, Richard
Lippmann, Richard Foley, and Roman Filippov. Paul Cochrane deserves
special thanks for reviewing and providing feedback on the blog posts
and manuscript and for being available to discuss content, ideas, and
organization matters.
I also want to thank my publishing team at Apress: Steve Anglin, Mark
Powers, and Matthew Moodie, as well as everybody doing awesome work
in the background, such as cover design, typesetting, and marketing.
Finally, thanks go to my parents, for kindling both my love for books
and engineering. And most important, to my family: to Signe, my wife, for
constant support; and to my daughters, Ida and Ronja, for keeping me
grounded in the real world and bringing joy to my life.

xv
Introduction
One of the keys to successful software development is getting fast
feedback. This helps developers avoid going down blind alleys, and in the
case of a bug that is revealed quickly, it can be fixed while the code is still
fresh in the developer’s mind.
On the business side, fast feedback also helps the stakeholders and
the product manager not to build features that turn out not to be useful,
thus avoiding wasted effort. Achieving a mutual understanding about
the desired product is a very difficult problem in any software project.
Showing a working (if partial) product early on often helps to eliminate
misunderstandings between stakeholders and developers.
There are many ways to add feedback loops on different levels, from
adding linting and other code checks in the IDE to agile processes that
emphasize incremental value delivery. The first part of this book focuses
on software tests and their automatic execution, a practice known as
continuous integration (CI).
When implementing CI, you set up a server that automatically tests
every change to the source code, potentially in multiple environments,
such as on combinations of operating system and programming language
versions.
The next logical step, and the topic of the second part of this book, is
continuous delivery (CD). After building and testing code, you add more
steps to the automated process: automated deployment to one or more test
environments, more tests in the installed state, and, finally, deployment to
a production environment. The last step is typically guarded by a manual
approval gate.

xvii
Introduction

CD extends the automation and, thus, the possibility for quick iteration
cycles, all the way into the production environment, where the software
can deliver value for you. With such a mechanism in place, you can quickly
obtain feedback or usage data from real customers and assess whether
expanding on a feature is useful or discover bugs while the developers still
remember the code that they wrote.
The code examples in this book use Python. Owing to its dynamic
nature, Python is well-suited to small experiments and fast feedback. The
well-stocked standard library and vast ecosystem of available libraries and
frameworks, as well as Python’s clean syntax, make it a good choice, even
for larger applications. Python is commonly used in many domains, for
example, web development, data science and machine learning, Internet
of things (IoT), and system automation. It is becoming the lingua franca of
professional programmers and those who just touch a subject to automate
some part of their job or hobby.
Python comes in two major language versions, 2 and 3. Because
Python 2 support is scheduled to end in 2020, and nearly all major libraries
now support Python 3, new projects should be started in Python 3, and
legacy applications should be ported to that language version as well,
if possible. Hence, this book assumes that “Python” refers to Python 3,
unless explicitly stated otherwise. If you only know Python 2, rest assured
that you will easily understand the source code contained in this book, and
transferring the knowledge to Python 3 is very easy.

I. 1 Intended Audience


This book is targeted at technical people involved in the software-delivery
process: software developers, architects, release engineers, and DevOps
engineers.

xviii
Introduction

The chapters that use source code examples assume basic familiarity
with the Python programming language. If you are familiar with other
programming languages, spending a few hours reading introductory
material on Python will likely bring you to a level at which you can easily
follow the code examples in this book.
The sample infrastructure uses Debian GNU/Linux, so familiarity with
that operating system is helpful, though not required.

I. 2 Code Examples


Code examples used in this book are available on GitHub under the
python-ci-cd organization at https://github.com/python-ci-­cd or via
the Download Source Code link located at www.apress.com/9781484242803.
Because some examples rely on automatically fetching code from
certain Git repositories, a split into several repositories is necessary.
Several chapters reference individual repositories under this namespace.

xix
CHAPTER 1

Automated Testing
Before diving into examples of how to test Python code, the nature of tests
must be discussed in more detail. Why do we want to have tests? What do
we gain from them? What are the downsides? What makes a good test;
what’s a bad test? How can we classify tests? And how many of which kinds
of tests should we write?

1.1 What Do We Want from a Test?


Why bother with writing tests at all? There are a number of reasons why we
want to write or, at least, have tests.
It is not uncommon to have several tests in a test suite, written in
response to different needs.

F ast Feedback
Every change to code comes with the risk of introducing bugs. Research
shows that somewhere in the range of 7% to 20% of all bug fixes introduce
new bugs.1

1
J im Bird, “Bugs and Numbers: How Many Bugs Do You Have in Your Code?”
Building Real Software: Developing and Maintaining Secure and Reliable
Software in the Real World, http://swreflections.blogspot.de/2011/08/
bugs-and-numbers-how-many-bugs-do-you.html, August 23, 2011.

© Moritz Lenz 2019 1


M. Lenz, Python Continuous Integration and Delivery,
https://doi.org/10.1007/978-1-4842-4281-0_1
Chapter 1 Automated Testing

Wouldn’t it be great if we could find those bugs before they find their
way to the customer? Or even before your colleagues see them? This is
not just a question of vanity. If you receive quick feedback that you have
introduced a bug, you are more likely to remember all the details of the
part of the code base you just worked on, so fixing the bug tends to be
much faster when you get fast feedback.
Many test cases are written to give this kind of fast feedback loop.
You can often run them before you ever commit your changes to the
source control system, and they make your work more efficient and keep
your source control history clear.

C
 onfidence
Related to the previous point, but worth mentioning separately, is the
confidence boost you can get from knowing that the test suite will catch
simple mistakes for you. In most software-based businesses, there are
critical areas where serious bugs could endanger the whole business.
Just imagine you, as a developer, accidentally mess up the login system
of a health-care data management product, and now people see others’
diagnoses. Or imagine that automatic billing charges the wrong amount to
customers’ credit cards.
Even non-software businesses have had catastrophic failures from
software errors. Both the Mars climate orbiter2 and the first launch of
the Ariane 5 rocket3 suffered the loss of the respective vehicle, owing to
software issues.

2
 ikipedia, “Mars Climate Orbiter,” https://en.wikipedia.org/wiki/Mars_
W
Climate_Orbiter, 2018.
3
J. L. Lions, “Ariane 5: Flight 501 Failure. Report by the Inquiry Board,”
http://sunnyday.mit.edu/accidents/Ariane5accidentreport.html, July 1996.

2
Chapter 1 Automated Testing

The criticality of their work puts emotional stress on software


developers. Automated tests and good development methodology can
help alleviate this stress.
Even if the software that people are developing is not mission-critical,
risk adversity can cause developers or maintainers to make the smallest
change possible and put off necessary refactoring that would keep the
code maintainable. The confidence that a good test suite provides can
enable developers to do what is necessary to keep the code base from
becoming the proverbial big ball of mud.4

D
 ebugging Aid
When developers change code, which in turn causes a test to fail, they want
the test to be helpful in finding the bug. If a test simply says “something is
wrong,” this knowledge is better than not knowing about the bug. It would be
even more helpful if the test could provide a hint to start debugging.
If, for example, a test failure indicates that the function find_
shortest_path raised an exception, rather than returning a path, as
expected, we know that either that function (or one it called) broke, or it
received wrong input. That’s a much better debugging aid.

D
 esign Help
The Extreme Programming (XP)5 movement advocates that you should
practice test-driven development (TDD). That is, before you write any code
that solves a problem, you first write a failing test. Then you write just
enough code to pass the test. Either you are done, or you write the next
test. Rinse and repeat.

4
 ikipedia, “Big ball of mud,” https://en.wikipedia.org/wiki/Big_ball_of_
W
mud, 2018.
5
Wikipedia, “Extreme programming,” https://en.wikipedia.org/wiki/Extreme_
programming, 2018.

3
Chapter 1 Automated Testing

This has obvious advantages: you make sure that all code you write
has test coverage and that you don’t write unnecessary or unreachable
code. However, TDD practitioners have also reported that the test-first
approach helped them write better code. One aspect is that writing a test
forces you to think about the application programming interface (API) that
the implementation will have, and so you start implementing with a better
plan in mind. Another reason is that pure functions (functions whose
return value depends only on the input and that don’t produce side effects
or read data from databases, etc.) are very simple to test. Thus, the test-first
approach guides the developer toward a better separation of algorithms
or business logic from supporting logic. This separation of concerns is an
aspect of good software design.
It should be noted that not everybody agrees with these observations,
with counterpoints from experience or arguments that some code is much
harder to test than write, leading to a waste of effort, by requiring tests
for everything. Still, the design help that tests can provide is a reason why
developers write code and so should not be missing here.

Specification of the Product


The days of big, unified specification documents for software projects are
mostly over. Most projects follow some iterative development model, and
even if there is a detailed specification document, it is often outdated.
When there is no detailed and up-to-date prose specification, the
test suite can take the role of specification. When people are unsure how
a program should behave in a certain situation, a test might provide the
answer. For programming languages, data formats, protocols, and other
things, it might even make sense to offer a test suite that can be used for
validating more than one implementation.

4
Visit https://textbookfull.com
now to explore a rich
collection of eBooks, textbook
and enjoy exciting offers!
Chapter 1 Automated Testing

1.2 Downsides of Tests


It would be disingenuous to keep quiet about the downsides that tests can
have. These downsides should not detract you from writing tests, but being
aware of them will help you decide what to test, how to write the tests, and,
maybe, how many tests to write.

Effort
It takes time and effort to write tests. So, when you are tasked with
implementing a feature, you not only have to implement the feature but
also write tests for it, resulting in more work and less time do other things
that might provide direct benefit to the business. Unless, of course, the
tests provide enough time savings (for example, through not having to fix
bugs in the production environment and clean up data that was corrupted
through a bug) to amortize the time spent on writing the tests.

Extra Code to Maintain


Tests are code themselves and must be maintained, just like the code that
is being tested. In general, you want the least amount of code possible that
solves your problem, because the less code you have, the less code must
be maintained. Think of code (including test code) as a liability rather than
an asset.
If you write tests along with your features and bug fixes, you have
to change those tests when requirements change. Some of the tests
also require changing when refactoring, making the code base harder
to change.

5
Chapter 1 Automated Testing

Brittleness
Some tests can be brittle, that is, they occasionally give the wrong result.
A test that fails even though the code in question is correct is called a false
positive. Such a test failure takes time to debug, without providing any value.
A false negative is a test that does not fail when the code under test is broken.
A false negative test provides no value either but tends to be much harder to
spot than false positives, because most tools draw attention to failed tests.
Brittle tests undermine the trust in the test suite. If deployment of a
product with failing tests becomes the norm because everybody assumes
those failed tests are false positives, the signaling value of the test suite
has dropped to zero. You might still use it to track which of the tests failed
in comparison to the last run, but this tends to degenerate into a lot of
manual work that nobody wants to do.
Unfortunately, some kinds of tests are very hard to do robustly.
Graphical user interface (GUI) tests tend to be very sensitive to layout or
technology changes. Tests that rely on components outside your control
can also be a source of brittleness.

False Sense of Security


A flawless run of a test suite can give you a false sense of security. This can
be due either to false negatives (tests that should fail but do not) or missing
test scenarios. Even if a test suite achieves 100% statement coverage of the
tested code, it might miss some code paths or scenarios. Thus, you see a
passing test run and take that as an indication that your software works
correctly, only to be flooded with error reports once real customers get in
contact with the product.
There is no direct solution for the overconfidence that a test suite can
provide. Only through experience with a code base and its tests will you
get a feeling for realistic confidence levels that a green (i.e., passing) test
run provides.

6
Chapter 1 Automated Testing

1.3 Characteristics of a Good Test


A good test is one that combines several of the reasons for writing tests,
while avoiding the downsides as much as possible. This means the test
should be fast to run, simple to understand and maintain, give good and
specific feedback when it fails, and be robust.
Maybe somewhat surprisingly, it should also fail occasionally, albeit
when one expects the test to fail. A test that never fails also never gives
you feedback and can’t help you with debugging. That doesn’t mean you
should delete a test for which you never recorded a failure. Maybe it failed
on a developer’s machine, and he or she fixed the bug before checking
changes.
Not all tests can fit all of the criteria for good tests, so let’s look at some
of the different kinds of tests and the trade-offs that are inherent to them.

1.4 Kinds of Tests


There is a traditional model of how to categorize tests, based on their scope
(how much code they cover) and their purpose. This model divides code
that tests for correctness into unit, integration, and system tests. It also
adds smoke tests, performance tests, and others for different purposes.

Unit Tests
A unit test exercises—in isolation—the smallest unit of a program
that makes sense to cover. In a procedural or functional programming
language, that tends to be a subroutine or function. In an object-oriented
language such as Python, it could be a method. Depending on how strictly
you interpret the definition, it could also be a class or a module.

7
Chapter 1 Automated Testing

A unit test should avoid running code outside the tested unit. So, if you
are testing a database-heavy business application, your unit test should
still not perform calls to the database (access the network for API calls) or
the file system. There are ways to substitute such external dependencies
for testing purposes that I will discuss later, though if you can structure
your code to avoid such calls, at least in most units, all the better.
Because access to external dependencies is what makes most code
slow, unit tests are usually blazingly fast. This makes them a good fit for
testing algorithms or core business logic.
For example, if your application is a navigation assistant, there is at
least one algorithmically challenging piece of code in there: the router,
which, given a map, a starting point, and a target, produces a route or,
maybe, a list of possible routes, with metrics such as length and expected
time of arrival attached. This router, or even parts of it, is something that
you want to cover with unit tests as thoroughly as you can, including
strange edge cases that might cause infinite loops, or check that a journey
from Berlin to Munich doesn’t send you via Rome.
The sheer volume of test cases that you want for such a unit makes
other kinds of tests impractical. Also, you don’t want such tests to fail,
owing to unrelated components, so keeping them focused on a unit
improves their specificity.

Integration Tests
If you assembled a complex system such as a car or a spacecraft from
individual components, and each component works fine in isolation, what
are the chances the thing as a whole works? There are so many ways things
could go wrong: some wiring might be faulty, components want to talk
through incompatible protocols, or maybe the joints can’t withstand the
vibration during operation.

8
Chapter 1 Automated Testing

It’s no different in software, so one writes integration tests. An


integration test exercises several units at once. This makes mismatches
at the boundaries between units obvious (via test failures), enabling such
mistakes to be corrected early.

System Tests
A system test puts a piece of software into an environment and tests it
there. For a classical three-tiered architecture, a system test starts from
input through the user interface and tests all layers down to the database.
Where unit tests and integration tests are white box tests (tests
that require and make use of the knowledge of how the software is
implemented), system tests tend to be black box tests. They take the user’s
perspective and don’t care about the guts of the system.
This makes system tests the most realistic, in terms of how the software
is put under test, but they come with several downsides.
First, managing dependencies for system tests can be really hard. For
example, if you are testing a web application, you typically first need an
account that you can use for login, and then each test case requires a fixed
set of data it can work with.
Second, system tests often exercise so many components at once
that a test failure doesn’t give good clues as to what is actually wrong and
requires that a developer look at each test failure, often to find out that
changes are unrelated to the test failures.
Third, system tests expose failures in components that you did not
intend to test. A system test might fail owing to a misconfigured Transport
Layer Security (TLS) certificate in an API that the software uses, and that
might be completely outside of your control.
Last, system tests are usually much slower than unit and integration
tests. White box tests allow you to test just the components you want, so
you can avoid running code that is not interesting. In a system test for a
web application, you might have to perform a login, navigate to the page

9
Random documents with unrelated
content Scribd suggests to you:
came outside of Manele. 97 He hou no keia mawaho ae o
noticed that their house was Manele. Ike aku la keia i ka hale
surrounded by a many-colored o laua ua paa i ka ua koko. A
cloud. When he arrived at his old hiki keia ilaila i kahi ana i lawaia
fishing ground his line and hook ai, ua moku aku la ke aho a ianei
were broken off. He returned and a me ka makau. Huli hoi mai la
when near shore he saw his wife keia a kokoke ike aku la keia i
standing on the seashore kana wahine e ku mai ana ma ka
beckoning to him. He said to aekai e peahi mai ana iaia. I iho
himself, “You are unaccountable, la keia iloko ona: “Kupanaha oe
my wife; you can see that I am e ka wahine, ua ike mai la no hoi
returning.” With one scoop of his ke hoi aku nei.” Hookahi no a
paddle in the sea the bow of the ianei kope ana i ke kai me ka
canoe landed on the sand. The hoe kau ana ka ihu o ka waa i ke
wife ran to him and grasped him one. Ia wa holo mai la kana
tremblingly. He asked, “What is wahine a apo mai la iaia, me ka
the cause of this heavy haalulu. Ninau ae la keia:
breathing?” She replied, with “Heaha hoi ke kumu o ka nui o
tears, “Our child has acted the ka hanu?” Pane iho la ia me ka
ghost to me.” “For what reason?” uwe: “Ua lapu ke keiki a kaua
“For this reason: soon after you ia’u.” “Heaha ke kumu?” “Eia ke
were gone I went to sleep and kumu, ia oe no hala aku nei, a
slept [558]soundly. A voice called, liuliu iki, ua keia loa wau e ka
‘Say, my dear mother, do thou hiamoe, kani ana kahea, ‘E! e
awaken; father is dead.’ I was ko’u mama aloha, e ala mai oe,
startled out of my sleep; I ua [559]make o papa.’ Ia wa
thought it was you. Not long after puiwa ae la wau mailoko mai o
that a voice chanted!” ka hiamoe, ua kuhi wau o oe, hoi
hou no wau a moe no, aole no i
The husband said, “Do you upu iho, kani ana ke oli.” I aku la
remember the chant?” “Yes,” ke kane: “Ua maopopo no nae
said the wife. paha ia oe ke oli ana mai?” “Ae,”
wahi a ka wahine.
How I desire the moisture of the Aloha au o kahi wai a ke kehau,
dew, Oia wai haaheo mai iluna o ka
The water proudly hanging on laau,
the tree; A ua mai ka ua i na pali,
When the rain falls on the E hoopiha ana i na kahawai,
precipice, O ka waiwai no ia a kuu maka o
It fills up the streams. ka ike aku,
That is the benefit my eyes A ike kuu maka a nehe kuu lima.
behold!
My eyes to behold, my hands to
rustle.

“Those are the queer things “Oia iho na hana kupanaha a ke


which our child did to me while I keiki a kaua ia’u i noho iho nei.” I
stayed here.” aku la kana kane: “Ina he oiaio
kena olelo au, e pomaikai ana
The husband replied, “If those kaua ma keia hope aku. Na ke
which you have stated are true au o ka manawa e hoike mai a e
we will be benefited hereafter. hooko, nolaila, e kali kaua ma
Time will show and bring them to keia hope aku.”
pass; therefore let us wait for the
future.” Hapai aku la laua nei i ka waa,
ua hele a piha u oloko o ka waa i
They lifted the canoe; it was ka i’a. Hoi aku la laua a hiki iloko
heavily laden inside with fish. o ka hale, hana iho la i ka i’a a
They returned, and reaching the miko i ka paakai; pulehu iho ka
house they salted the fish; the wahine i kekahi i’a a moa,
wife broiled some and when hoomakaukau iho la laua i ka ai
done the two prepared to eat; ana, pule ae la laua ma ka inoa
they prayed to this child as o ua keiki nei, a penei:
follows: “In the name of
Puupehe, grant us eternal life. “Ma ka inoa o Puupehe e ola
Amen. It is free.” mau loa maua. Amama, ua noa.”
They ate until satisfied, then Ai laua nei a maona,
made preparations for sleeping. hoomakaukau no na mea e pili
While they slept that night the ana no ka moe ana, a i ko laua
child went to watch what one moe ana iho i ka po, o ka hana a
man was doing; he was teaching ua keiki nei o ka hele e makaikai
his pupils the art of casting the i na hana a kekahi kanaka, e ao
spear, and how to fly on to a ana ia i kana poe haumana i ka
water gourd, and so forth. He oo ihe, a me ka lele ana iluna o
was teaching them with the idea ka ipu huawai, a pela uku. E ao
that when proficient they were to ana a ike hele e kaua me kona
fight with his parents, mau makua me Kapokoholua
Kapokoholua and his wife. ma.

When the child had gone the I ka hele ana a ua keiki nei, ua
womb of Kapoiliili contracted, mimino iho la ka opu o Kapoiliilii,
and she said to her husband, olelo aku la ia i ke kane: “E ianei
“Where are you? Please feel my e! e haha mai oe i kuu opu.”
belly.” The other felt of it: “Why, Haha mai la ia: “E, ua emi iho
your stomach has shrunken!” nei ka ko opu.” “Kupanaha,”
“Strange!” said the wife. The wahi a ka wahine. I aku la kana
husband said, “Do not be kane: “Mai haohao oe ua hele
troubled, he has gone to see the aku la e makaikai ma kela wahi
different parts of the world.” They keia wahi o ka honua.” Hoi iho la
retired awhile for a short rest, laua hoonanea iki, kani ana
when the child called out: “You kahea a ua keiki nei: “E laua nei
two, awake, light the lamp.” They e, e ala, e hoa i ke kukui.” Ala ae
awakened and lit the lamp. “You laua hoa aku la i ke kukui. “E
two smoke up some tobacco for puhi mai olua i paka no’u, a e
me, and chew my piece of awa mama iho i kuu wahi opuupuu
root; it is above the door.” awa, aia maluna ae o ka puka.”

They were puzzled, because Hoaa iho la laua, no ka mea,


they did not drink awa; therefore aole he inu awa o laua, nolaila,
they were undecided as to what pahaohao laua no ia mea, pane
to do; the child spoke with heat, mai la ua keiki nei, me ka huhu:
“Why are you two so slow? [for I “E aha ana ka hoi olua e lohi nei,
wish to] go on my business of a hele au i ka’u hana o ka
sightseeing.” His father hastened makaikai.” Ua hooko koke aku la
to obey, and when everything kona makuakane a makaukau
was ready [the child] na mea i hana ia, kena mai la e
commanded him to pray. The pule; pule ae la ka makuakane e
father uttered the same prayer like me kana pule mua ana,
which he offered before; the hoole mai la ia. “Aole ia o ka
other wouldn’t have it so. “That pule e ola ai ke hiki mai ka pilikia
prayer will not save when trouble ia olua.” I aku la ia: “Pehea ka
comes to you two.” The father pule e ola ai?” “Penei, e
asked, “What is the prayer which hoopaanaau oe.” Hai mai la ia:
will save?” “Thus, and you must
learn it by heart:

Here is food, O Puaiki! 98 Eia ka ai e Puaiki e.


Curse those who deal falsely, Molia i ku ia i ka hoopea wale,
Who are envious, I ka awaha wale mai,
Who wish us death! I ka make wale mai,
Here I am, Kapokoholua! [560] Owau nei o Kapokoholua, [561]
Life for me until I walk with a E ola ia’u a kanikoo;
staff: O kau ola ia e ka akua.
That is your life, O god!

When they had learned it by A pau keia hoopaanaau ana a


heart the father ate by himself; laua nei, ai iho la no ua
for it is the father who eats; the makuakane nei, oia wale no, no
child only made a pretense of ka mea na ka makuakane e ai; i
eating; that was what was done ke aka wale no ka ua keiki nei e
when he asked anything of his ai mai; pela kana mau mea e
parents. When the father had makemake ai e olelo mai ai i
finished eating, the child called kona mau makua. A pau ka ai
for the second kind of food, that ana a ua kanaka nei, kahea mai
was the tobacco. After smoking la no ua keiki nei i ka lua o ka ai,
the tobacco the child returned to oia ka paka. A pau ke puhi ana o
the womb of the mother. The ka paka, hoi ae la ua keiki nei
womb of Kapoiliili became as iloko o ka opu o ka makuahine,
large as it was formerly. The wife nui hou ae la ka opu o Kapoiliilii
said, “I think perhaps the child a like me mamua. I mai la ka
has returned to my womb.” “Why wahine: “Hoi hou mai nei paha
so?” asked the husband. “I am ua keiki nei iloko o’u.” “Ke aha
swelling,” replied the wife. “Do la?” wahi a ke kane. “Ke pehu ae
not wonder, because he is nei,” wahi a ka wahine. “Mai
satisfied; he has returned to rest, hoohuoi oe, no ka mea, ua
and when his fullness is maona kela hoi ae la kela e
lessened he will go about his hooluolu a emi iho kekahi
business of sightseeing.” maona, hele aku kela i ka iala
hana o ka makaikai.”

The wife was no longer afraid; Pau wale iho la no ka makau o


perhaps she was a little fearful of kana wahine, no ke ano makau
her husband. And when it was paha i ke kane. A i ke kokoke
nearly morning the child went off ana e ao ae ua po nei, ua hele
again as usual. I will leave this ua keiki nei elike me ka mea i
part until later. I wish to speak of hala ae nei mamua. E waiho iki
the [number of] months this child au i keia a mahope aku, e
was in the womb of his mother, kamailio aku wau no na malama
and the cause of its going about o keia keiki iloko o ka opu o ka
while still in the womb. This child makuahine, a me ke kumu o ka
had been thirteen months in the hele ana i ka wa no iloko o ka
womb when it acted in a ghostly opu.
manner to his mother, as stated
heretofore. They (the parents)
had wondered why the child was O na malama o keia keiki iloko o
not delivered, because the time ka opu he umikumamakolu, i ka
for the delivery of the child, wa i lapu ai i kona makuahine, i
twelve months, had passed. With olelo mua ia ae nei. Ua lilo no ia
their child there was no birth. In he mea haohao ia laua, no ke
this matter they were greatly in kumu o ka hanau ole, no ka mea
suspense [and were surprised], ua hala ka palena o ka hanau
because it walked about while ana he umikumamalua; i ka laua
still in the womb; its face was not keiki hoi aohe hanau iki. Ma keia
seen; it talked as if it were a mea, ua kanalua loa no hoi laua;
shadow at a distance. a no ka hele ana, aia no iloko o
ka opu, aole nae he ike ia o ke
ano a me kona helehelena, o ke
kamailio aka wale mai no ma
kahi e.

[unfinished.] [aole i pau.]

A STORY MOOLELO NO KE AHI.


CONCERNING THE
FIRE.

This is the way the fire was Eia ke kumu o ka loaa ana mai o
obtained, according to some ke ahi, wahi a kekahi poe, penei:
people. Maui took to wife Hina O Maui kai noho ae ia Hina
and begat Mauimua, 99 hanau mai o Mauimua, a me
Mauihope, 100 Mauikiikii 101 and Mauihope, a me Mauikiikii, a me
Mauiokalana; 102 they were all Mauiokalana, he poe keiki kane
boys. The occupation of these wale no keia. O ka hana a keia
boys was fishing. This was their poe keiki he lawaia. Penei ka
practice in fishing while living at lakou lawaia ana, ia lakou nei e
Kaupo, Maui: Mauiokalana noho ana ma Kaupo, i Maui,
wished to go fishing; he said to makemake iho la o Mauiokalana
his elder brothers: “Say, this is a e holo i ka lawaia; olelo aku i
calm day; shouldn’t we sail the kona poe kaikuaana: “E, kai ka
sea? for this is a good day, the malie o keia la, holo paha kakou
sea is calm; this is a day when i kai, nokamea, he la maikai
the tide is not strong in its keia, ua hele a malino ke kai, a
opposition for it is flowing in one he la ikaika ole o ke au i ke pale,
direction.” When he had finished a he la moekahi o ke au.” A pau
speaking, Mauimua answered: ka ianei olelo ana, pane mai la o
“Let us not sail, for this will be a Mauimua: “Aohe make holo o
tempestuous day; this calmness kakou, nokamea, he oi keia o ka
which we see is only in the la ino, o keia malie a kakou e ike
morning; when the sun rises you aku nei, he malie kakahiaka, ai
will see the waves rise, the wind aenei keia a kau ae ka la, alaila,
will increase, and in a short time ike aku oe e okaikai mai ana, a o
we will be obliged to return. Put ke ala mai no ia o ka makani,
off your fishing until a calm day.” aole e emo ka hoi koke mai no ia
Then Mauiokalana spoke again: o kakou. E waiho no ka lawaia a
“Why, I thought because you are hiki i ka la maile.” Alaila pane
the first-born you knew the signs hou mai la o Mauiokalana: “E, ke
of the sky, but I see you do not! kuhi nei au i kou hanau mua ike
Your yellow teeth signify oe i na ouli o ke ao, eia ka aole,
nothing.” Then Mauimua, he lenalena niho wale iho no
displeased, answered: “Say, my kou.” Alaila pane hookuakaeo
younger [562]brother, you do not mai la [563]o Mauimua: “E, auhea
realize that I am the one oe e ka pokii, aole oe i ike, owau
acquainted with the ways of this mai ka mea i kamaaina i ke ano
place. This is the sign I know o keia wahi; penei ka’u ouli i ike
about: when you sleep until near ai, aia moe aku oe a hiki i ka
morning, and should hear the wehe ana o kai o ke ao, a i poha
breaking surf above the wind, mai ka nalu iloko o ka makani,
then it will be calm. That is my alaila e malie aenei; oia ka’u
sign, that you may hear, my ouli, i lohe oe, e kuu pokii.
younger brother. But what of it? Heaha la nei hoi; e holo paha
let us sail according to your kakou mamuli o kau koi.”
urging.” Mauimua ordered the Hoolale ae la o Mauimua e hapai
canoes lifted to the beach. The na waa i kai. Hapai ia aku la no
canoes were taken to the shore, hoi na waa a hiki i ke kai, alaila
and they prepared to sail for makakau iho la lakou no ka holo
fishing. When they arrived at the i ka lawaia. Ia lakou nei i hiki aku
reef they saw a fire burning on ai i kohola ike aku la lakou nei i
land. Then Mauiokalana said to ka a mai o ke ahi o uka, alaila
his elder brothers: “Say, there is olelo mai la o Mauiokalana i
a fire burning; whose fire can this kona poe kaikuaana: “E, ke a
be?” The others replied: “Whose mai la ke ahi, nawai la hoi keia
indeed? Perhaps we had better ahi?” I mai la no hoi lakou:
return so we can cook some “Nawai hoi; e hoi paha kakou i
food for us.” “Pshaw! Let us first moa ona ai na kakou.” “Ka! e
go and get some fish, then holo kakou a loaa mai ona ia,
return; so that when we get back alaila lea ka hiamoe, ua moana.”
with fish we can broil them, cook Holo aku la lakou nei; aole i emo
the food, and then [we can] loaa mai la na ia. O ka hoi iho la
sleep well, being satisfied.” They no ia. A ia lakou nei i hiki aku ai i
went on; in no time they had kahakai, haalele iho la o
caught some fish. They then Mauimua i ka waa, a holo aku la
returned. As soon as they arrived e nana i kahi i a ai o ke ahi. Ike
at the beach Mauimua left the mai la o Kaalaehuapi, o ko lakou
canoe, and ran to where the fire kuehu ae la no ia i ke ahipio, pau
was seen burning. aku la lakou la i ka lele. Hoka iho
Kaalaehuapi 103 saw him so he la o Mauimua, hoi mai la a hiki i
and the others threw dirt on the ko lakou hale; ninau mai la ko
fire and smothered it, and flew lakou poe: “Pehea mai nei ka hoi
away. Mauimua was ke ahi?” “Aohe ahi, ua pio, ke
disappointed; he returned to their kuhi nei au he kanaka, eia ka
house. The others asked, “How aole, he alae ka mea nana ke
about the fire?” “There is no fire; ahi. O ka maia a kakou, ua pau i
it is put out; I thought it was man, ka aihue ia.” No ko lakou nei ike
but it was not; some mudhens ana i ka pau i ka aihue ia o ka
kindled the fire. Our bananas are maia, nolaila aole o lakou hele i
being stolen.” Because they saw ka lawaia, me ka manao e a hou
that their bananas were being mai ke ahi. Eia nae aohe a iki o
stolen they did not go fishing; ke ahi. Nolaila, holo hou lakou i
they hoped the fire would be ka lawaia; aia holo lakou nei i ka
kindled again, but it was not lawaia, alaila e a auanei ke ahi.
lighted. Then they went fishing Pela lakou nei i hooluhi ia ai,
again. Whenever they went out aohe loaa iki; nokamea, ua
fishing the fire would burn. Thus maopopo ia Kaalaehuapi eha no
were they harassed, but they keiki a Maui laua me Hina. I ka
could not get anything, because wa e holo ai i ka lawaia, helu aku
Kaalaehuapi knew that Maui and o Kaalaehuapi i ka nui o lakou; a
Hina had four sons. When they pau pono, alaila hoa ke ahi.
went fishing Kaalaehuapi
counted them; when they were
all present it would light the fire.

But Maui thought of a plan and Aka, mamuli o ka noonoo ana a


he said to his brothers, “Say, Maui ua olelo aku oia penei: “E,
tomorrow morning you go apopo a kakahiaka holo oukou i
fishing; I will remain. You will ka lawaia, owau o kakou ke
place our calabash in front noho; alaila o ka hokeo a kakou
where I sit. You will cover it with mamua ia o ko’u wahi e noho ai.
kapa. Then you will go to sea.” E uhi oukou a paa i ke kapa,
The others consented and they alaila holo aku oukou i kai;” ae
went. Kaalaehuapi saw them mai la no hoi lakou, o ka holo iho
and counted Mauimua, la no ia. Ike mai la o
Mauihope, Mauikiikii, Kaalaehuapi, helu mai la oia
Mauiokalana. He counted all Mauimua, Mauihope, Mauikiikii,
present, so the mudhens lighted Mauiokalana; ike iho la oia ua
the fire and roasted the bananas. pau pono, alaila ho-a ae la ua
Before the bananas were poe alae nei i ke ahi, pulehu ka
cooked, Kaalaehuapi said, “Say, maia. Aole hoi i moa iho ka
they’re done; Hina’s son is swift.” maia, olelo mai o Kaalaehuapi:
It was then Maui jumped to grab “E, ua moa, he keiki mama ka
and caught Kaalaehuapi. Then Hina.” Ia manawa lele aku la o
he said, “I will kill you, you Maui e hopu, a paa iho la o
mudhen. You folks indeed have Kaalaehuapi. Olelo aku la o
the fire and you are hiding it. I Maui: “Make oe ia’u e kena alae;
will kill you, you mudhen. eia no ka hoi ke ahi ia oukou e
Kaalaehuapi said, “If I die, the huna nei. E make ana oe ia’u e
fire can not be obtained.” The kena alae.” Olelo mai la o
other mudhens called out, “O Kaalaehuapi: “Ina au e make,
Kaalaehuapi, hold on to the fire; aole e loaa ke ahi.” Alaila no hoi
do not tell.” Maui commenced to kahea mai ka nui o na alae: “E,
twist the neck of the mudhen, Kaalaehuapi, e paaia ke ahi; mai
planning to kill it dead there and hai oe.” Hoomaka iho la o Maui
then. The mudhen again spoke: e wili i ka puana-i o u wahi alae
“Grant me life, then you will nei, me ka manao e pepehi a
obtain the fire.” Maui asked, make ia manawa. Olelo hou ae
“Where is the fire?” “In the stalk la ua wahi alae nei: “E ola au
of the ape leaf.” So he went to alaila loaa ia oe ke ahi.” I mai la
rubbing, but it would not light; he Maui: “Aihea ke ahi?” “Aia iloko
asked again, “Where is the fire?” o ka ha o ka ape.” O ko ianei
The other directed: “In the stalk hoomaka iho la no ia i ka hiahia,
of the taro leaf.” He again went aole a iki; olelo hou aku la no
to rubbing, but it would not light; keia: “Aihea ke ahi?” Kuhikuhi
the stalk of the taro leaf became hou mai la kela: “Aia i ka ha
grooved, but no fire was kalo.” Noke no keia i ka hiahia
produced; that is why the stalk of aohe no he a; o ka ha o ke kalo
the ape and the taro leaf has a kai hele a poopoo, aohe a iki; o
groove, because of Maui’s ka mea ka ia i owawa ai ka ha o
rubbing for fire. Again he asked, ka ape, a me ke kalo, no ka hia
“Where is the fire which you are ana o Maui i ke ahi. Alaila ninau
hiding?” “In the green wood.” He hou no keia: “Aihea ke ahi au e
rubbed that, but it would not huna nei?” “Aia i ka laau maka.”
ignite. Again he asked. He kept Noke no keia i ka hiahia aohe no
doing this until it [564]came to the he a. Ninau no keia. Pela [565]ka
dry wood; there he found the fire. hana ana a Maui a hiki i ka laau
When he had produced fire, he maloo, loaa ke ahi. Ia loaa ana o
rubbed the head of the mudhen. ke ahi, e hiahia aku ana keia i ka
That is why the mudhen has a lae o ua wahi alae nei; oia ka ula
red head as we see it now. And o ka lae o ka alae a kakou e
from that time was fire obtained nana aku nei. A mai ia manawa
and has been handed down to mai ka loaa ana o ke ahi a hiki i
the present time. keia la.

Fire is used to cook food and O ka hana a ke ahi, he mea e


fish. It also helps in the work of moa ai ka ai, ka ia, oia no hoi
man, because in cultivating kekahi mea e kokua ana i ka
some people use fire [to burn off hana a ke kanaka, nokamea, o
rubbish] before planting the ka mahiai ana a kekahi poe me
leaves. The fire has various ke ahi e puhi ai i ka mala uala,
other uses; they can not all be alaila kanu aku ka lau. He nui
explained because the time is aku no na hana a ke ahi aole e
limited. pau i ka weheweheia aku,
nokamea he uuku ka manawa.
R. Puiki.
R. Puiki.
A STORY OF MAKAHI. HE MOOLELO NO
MAKAHI.

Hamau 104 was the father and O hamau ka makuakane, o


Hooleia 105 was the mother. A son Hooleia ka makuahine, hanau
was born to them; that is the mai ka laua keiki, oia keia a
subject of this story. They lived kakou i lohe ae nei i ka mea
at Puako, Hawaii. The first-born nona keia moolelo. O ko lakou
of these people was a daughter. nei wahi i noho ai, aia ma Puako
Luukia was her name. Sixteen i Hawaii. O ka mua o keia hanau
years after she was born she ana mai a keia mau makua, he
went to Oahu. Before she went kaikamahine, o Luukia ka inoa,
to Oahu, however, the mother hanai ia ua kaikamahine nei, a
was pregnant with Makahi; but hiki i ka umikumamaono o kona
she went off before the child was mau makahiki, hoomaka oia e
born; after a while it was holo i Oahu. Mamua nae o kona
reported back that she was holo ana i Oahu ua hapai ua
married, the husband’s name makuahine nei ia Makahi, o ko ia
being Kamauoha. 106 nei holo ihola no ia i Oahu me ka
ike ole i ka hanau ana, a liuliu iki,
lohe ia mai ana ua male i ke
kane. O ka inoa o ke kane o
Kamauoha.

At the time that he married this Aia i ko ia nei wa i male ai i ka


woman tales of his prodigious wahine, ua kui ia akula ko ia nei
strength in casting the spear ikaika ma Oahu apuni, no ka
were carried all round Oahu, and ikaika i ka o-o ihe, a ua lilo ia i
he became a famous man on mea nui ma Oahu. O ka nui o na
Oahu. The property of very many kanaka ua pau ko lakou waiwai i
people was won by this strong ka lawe ia e keia kanaka ikaika,
man. He had many friends, and ua nui na hoa aloha a ua nui no
also great wealth. After they hoi kona waiwai. Mahope iho o
lived for some time an idea ko lakou noho ana a liuliu, kupu
occurred to Kaaiai, 107 a man of maila ka manao iloko o kekahi
Ewa, Oahu, who wished to test kanaka, oia o Kaaiai, no Ewa,
his strength. He came and stood Oahu, hoao maila oia i kona
in the presence of Kamauoha ikaika, hele maila oia a ku i mua
the warrior, and spoke o ua kanaka koa nei o
animatedly, thinking that he Kamauoha, a pane maila me ke
could win. 108 Kamauoha said: ano hooikaika, me ka manao
“What is the main reason for paha e eo ana la iaia. Olelo mai
coming here?” He replied: “I o Kamauoha: “Heaha kau
came to see which of us is the kuleana nui o ka hiki ana mai o
stronger.” The other asked: “How onei?” Hai aku keia: “I hele mai
shall we test strength?” “By nei au e hoao i na ikaika o
piercing with spears,” replied kaua.” Hai aku la keia: “Heaha
Kaaiai. Kaaiai’s property ka ikaika e hoao ai?” “O ka o o
consisted of three narrow strips ihe,” wahi a Kaaiai. O ka nui o
of land, six sets of scented kapa, na waiwai o ua Kaaiai nei, ekolu
eight dogs, fifty hogs, four mooaina, eono kuinakapa o-u
houses; those were what the holowai, ewalu ilio, he kanalima
man’s property consisted of. puaa, eha hale, oia ka nui o ka
When they tried, Kamauoha waiwai o ua kanaka nei. I hoao
inflicted the first pain; 109 all the iho ka hana, eha mua akahi ia
man’s property was Kamauoha, lawe ia aku la na
completely 110 taken over by the waiwai o ua kanaka nei, puehu
opponent, and he returned ma kela aoao, hoi nele akula
empty handed to his house. keia a hiki i ka hale. Olelo maila
ka wahine: “Pehea maila kau
His wife asked, “And how was huakai?” “Pehea mai ka hoi kau,
your journey?” “You ask how, o na wahi waiwai no hoi a kaua i
indeed! The properties which we hoiliili iho nei me ka manao la
accumulated thinking that they hoi e hoonui hou ia mai ana, eia
would be added to were taken ka o ka hao ia aku nei no ia a hoi
from me, and I returned stripped; nele mai nei au, ua ike ia no la
the other’s strength was known ko iala ikaika, hoonaulu wale aku
and yet I dared provoke him, nei no keia, me ka manao la hoi
hoping to benefit thereby.” e loaa mai ana ka pomaikai.”

Let us leave off consideration of Nolaila, e waiho iki iho kakou no


this brave man and this daring ke kamailio ana no ke koa ikaika
fellow, and speak of the child in a me keia kanaka hoaano, a e
the womb of the mother at kamailio ae kakou no ke keiki
Hawaii. When the child was iloko o ka opu o ka makuahine i
born, a female prophet saw that Hawaii. Aia i ka hanau ana mai o
this was to be a strong child, and ua keiki nei, ike e maila kekahi
no one who dared him could luahine akamai i ka nana, he
escape. The name of this old keiki ikaika, aole e pakele ka
woman was Kolea, and she lived mea hana wale aku iaia. O ka
near the home of the child’s inoa nae o keia luahine o Kolea,
parents. The child was brought ua kokoke no kona wahi noho
up until he had attained me ko na makua o ua keiki nei.
manhood, when [566]the desire Hanai ia ihola ua keiki nei a nui,
seized him to go sightseeing. He a kupu aela ka manao iloko o ua
said to his father, “I am desiring keiki nei e hele i ka makaikai,
to go sightseeing.” The father [567]a ninau aku i ka makuakane:
said: “Where do you wish to “Makemake mai nei ka hoi au, e
travel to?” He replied: “Along hele i ka makaikai.” A olelo mai
here, somewheres.” The father ka makuakane: “Mahea kau
said: “If you wish to go makaikai e hele ai?” Hai mai
sightseeing, your sister is at an kela: “Ma keia wahi aku nei la.”
island ahead here, at Kauai.” Olelo mai kela: “Ina oe e
The son asked: “What is the makemake e hele, aia ko
name of the place where they kaikuahine ma keia mokupuni
are living?” The father told him, aku nei la, aia ma Kauai.” Olelo
“At Mana, Kauai.” He waited for mai ke keiki: “Heaka ka inoa o
some time. Again the father said, kahi a laua e noho nei?” Hai mai
“Should you go, and your sister ko makuakane: “Aia ma Mana i
does not recognize you, tell her Kauai.” O koia nei noho ihola no
about us, and she will then know ia a liuliu, hai mai ka
you.” He agreed to do so. They makuakane: “A i hele oe ea, a i
lived together until the aspiring hoohewahewa mai ko
one went on his journey of kaikuahine ia oe, e hai aku oe ia
sightseeing. The father first maua, a nana ia e ike mai ia oe.”
secured the club on which their Ae aku nohoi keia. O ko lakou
calabashes were hanging, and nei noho pu ihola no ia, a hiki i
gave it into the hands of the lad. ka wa i hele ai ua eueu nei i
He was taught how to cast the kana huakai makaikai, kii e aku
spear, until it was seen that he la nae ka makuakane i ka laau
was very proficient. He then kau paipu a lakou nei, a haawi ia
went along, carrying the club ma ka lima o ua keiki nei, a oia
with him. He made a circuit of ihola nae ua keiki nei i ka
Hawaii. Finding a canoe about to pahupahu ihe, a ike maoli ia
sail for Maui he went and stood nohoi ua keiki nei i ka
at the landing place. The men of makaukau. O ko ia nei hele
the canoe saw what a handsome maila no ia, paa pu maila no nae
man he was. The names of the me ua laau nei. Hele keia a puni
owners of the canoe were o Hawaii, a ike keia he waa e
Liuliu, 111 Makaukau and Aumai. holo ana i Maui, o ko ia nei hele
The men said to the lad, “Where akula no ia a ku ana i ke awa.
are you journeying to?” “Sailing Ike maila na kanaka o ka waa i
for Maui; and I came to inquire ke keiki kanaka maikai o ia nei; o
concerning your canoe; where is ka inoa o na kanaka nona ka
it bound?” “We are sailing for waa, o Liuliu, o Makaukau, o
Maui,” they replied. They sailed Aumai, oia ka inoa o na kanaka.
together and arrived at Maui. Olelo aku ua mau kanaka nei i
Their canoe landed at Kukui, ke keiki: “E hele ana kau huakai
Kipahulu. He (the lad) came mahea?” “E holo ana i Maui a i
along and slept at Pelekane, hele mai nei hoi e ninau i ko
Lahaina. When he found a oukou waa, e holo ana la i hea?”
canoe going to Molokai, he “E holo ana i Maui,” wahi a ua
sailed in it and was landed at poe nei. O ko lakou nei holo
Halawa, Molokai. He went maila no ia, a ku ana i Maui nei,
sightseeing, and because of the ma Kukui, i Kipahulu, kahi i kau
heat of the sun he went in ai o ka waa o lakou nei. Hele
bathing. The name of the place maila no keia a moe ma
where he bathed is Hakawai. He Pelekane, i Lahaina nei, a ike he
left his club on the bank. A man waa e holo ana i Molokai, e e iho
arrived and took it saying, “I no keia a holo aku a pae ma
have found something at Halawa, i Molokai; kaapuni keia,
Hakawai.” Then the lad said to a no ka nui o ka wela o ka la,
the man, “You are taking my hele keia e auau. O kahi aia nei i
club; mine is the next [move] auau ai oia o Hakawai. Kapae
when I shall kill you.” The man aela keia i ka laau aia nei, hiki
had a spear. The lad followed ana kekahi kanaka a lawe ana i
him; when the man threw the keia laau, me ka olelo iho: “A ma
spear at the boy the latter caught ka’u mea haule wale i Hakawai.”
it first at the point; in returning it Ia wa olelo aku ua keiki nei i ua
the man was struck in the pit of kanaka nei: “Ke lawe ala oe i
the stomach and the spear kuu laau, na’u aku koe, make oe
pierced the back. The lad stuck ia’u.” He laau no nae ka ua
the butt of the spear in the kanaka nei, o ko ia nei hele aku
ground and impaled the man on la no ia mahope, i pahu ’ku hana
it. He kept on his journey. o ua kanaka nei paa e ka welau
Arriving at Kaunakahakai his o ka ihe a ua kanaka nei ia ia
spear was taken by one of the nei, pahu ia aku ua kanaka nei,
champions of the place to a ku ma ka opu a hula ma ke kua,
cave. No sooner had the other hou ia ihola nae ke kumu o kana
entered the cave than the lad ihe i ka lepo me ua kanaka nei.
also appeared and asked for his Kaapuni keia a hiki ma
spear; but it was not given him. Kaunakahakai, lilo ka ihe aia nei
He closed the mouth of the cave; i kekahi kupu eu olaila, lawe ia
when there was a small opening akula a komo kela i ke ana,
left, he lighted a fire. On account komo no keia i ke ana, nonoi aku
of the heat in the cave from the keia, aohe he loaa mai. Papani
fire, the local champion thrust keia i ka puka o ke ana, a ueeku
out the point of the spear. The ka puka i koe, ho-a keia i ke ahi
boy caught and jerked it, but the a no ka nui loa o ka wela o ke
tip was already burned. He went ana i ke ahi, o nou maila ua
along until he found a canoe kupueu nei i ka welau o ka ihe, a
sailing for Lanai. He boarded this o ko ia nei huki maila no ia, ua
canoe and met Pololu. He did pau nae ke poo i ke ahi. Hele
not tarry long at this place. He maila no keia a ike keia he waa
again boarded the canoe which holo ana i Lanai, e e keia
brought him from Molokai and maluna o ua waa nei a halawai
sailed for Oahu, landing at Ewa. me Pololu, aole keia i noho liuliu
He stayed there for some time, malaila, o ua waa nei no ana i
then sailed for Kauai and landed holo mai ai mai Molokai mai, e e
at Wailua, but kept on until he no keia a holo ma Oahu a pae
arrived at Mana. He asked a keia ma Ewa, noho keia a liuliu
woman whom he met, “Do you iki malaila, holo keia i Kauai a
know Kamauoha?” “Yes; this is pae i Wailua. Hele akula no keia
his house by which we now a pae ma Mana, ninau keia i
stand.” He turned in there; kekahi wahine e hele mai ana,
arriving at the door of the house “Ua ike anei oe ia Kamauoha?”
he noticed that inside the house “Ae, o ka hale iho no kena a
was full of people. His sister kaua e ku nei.” O ko ia nei kipa
called, not knowing that this was akula no ia malaila, a ku ana ma
her brother. She asked, “From ka puka o ka hale, i nana ’ku
where did you come?” He auanei ka hana o ua keiki nei, ua
replied, “I came from Hawaii, hele oloko a piha i na kanaka.
seeking for my sister Luukia.” Kahea no ke kaikuahine oia nei
[568]The other asked who his me ka ike ole nae o ua
parents were, and he explained kaikuahine nei o ke kaikunane
all from the beginning to the end. keia. Ninau maila kela, “Mai hea
So they began to wail. They mai nei oe?” Hai akula keia: “Mai
wailed from that day to night, Hawaii mai nei au, e imi ana i
and all through the night to the kuu kaikuahine ia Luukia.” Ninau
next day. The husband of the pono maila nae kela i ko ia nei
sister thought that this was a [569]makua, hai akula nohoi keia
lover of hers. Then he told the mai ka mua a ka hope. O ko
people to prepare food; at the laua nei uwe ihola no ia ma ia la
same time he instructed them: a po, ma ia po a ao. Manao ke
“When you have prepared food kane a ua wahine nei, he kane
and the finger bowl is set in the keia nana, ia manawa. Olelo
middle, I will call him to come keia i na kanaka: “E
and eat; when he washes his hoomakaukau i ai, me ka olelo
hands in the basin, then I will say aku nae o ua kanaka nei: “I
this: ‘You are washing your hoomakaukau a ua nei kakou i
hands; for what purpose?’ When ka ai, me ke poi wai holoi a ku
he replies, I will turn to you, and mawaena nei, kahea anei au e
that will be your cue to deride hele mai e ai, i holoi a ua nei ka
him.” The food was prepared, as lima i ke poi wai holoi, alaila,
well as the basin for washing the olelo a ua nei au me keia: “Holoi
hands in. The lad was called, ka lima, heaha ko alaala? Nana
and he came; and while washing auanei e pane mai, ui auanei au
his hands the brother-in-law ia oukou, na oukou ka hoi ia e
spoke: “You are washing your olelo mai. Hoomakaukau ia ihola
hands; for what purpose?” The ka ai me ka poi wai holoi.”
lad answered, “I was called by Kahea ia akula nohoi ua keiki nei
those in that corner and this o ko ia la hele maila no hoi ia, a
corner to move up to the middle.” holoi nohoi ka lima. Pane no ua
“Is that so? Was this one called kaikoeke nei: Holoi ka lima,
to come and eat?” asked the heaha ko alaala?” Pane no hoi
evil-minded brother-in-law. “No,” ua keiki nei: “I kahea ia ae nei
replied the others. “How I am hoi i kela kihi keia kihi e kaikuwai
shamed!” Without touching the e waenakonu, pela anei.” “I
food, he returned to where he kahea ia aku nei anei e hele mai
had previously lain, without e ai.” Peia ka olelo a ua
saying a word to the sister. kaikoeke manao ino nei. “Aole,”
wahi a kela poe, “U, hilahila ino,”
o ko ia nei hoi akula no ia me ka
ia ole, ma ko ia nei wahi i moe
ai, me ka ekemu ole aku i ke
kaikuahine.

[unfinished.] [aole i pau.]

August 22, 1872. Iosia August 22, 1872. Iosia


Waalani. [507] Waalani. [570]

1 This series of Lahainaluna School


papers is presented as written,
without liberty taken therewith of
alteration for facts, or for completion of
several unfinished. They afford interest
and some value as the natural product
of Hawaiian pupils, as compositions on
the various subjects assigned them. It
was through just such a method that
the material for the original history of
these islands was secured, and by the
same school, some twenty-five years
earlier. ↑
2 Bones of Pele. This is the name of a
hill near the shore, to the south of
Kauiki. ↑
3 Oopus, gobies (Eleotris fusca). ↑
4 Offerings for the god. ↑
5 An image in human form. ↑
6 Opule (Anapses evermanni). ↑
7 Ha, a water course or trough. ↑
8 Fish thrown aside was afterward
taken and offered up as a sacrifice,
being the “first fruit” of the ha or
trough. ↑
9 Apua, a wicker fishing basket,
somewhat bell-shaped. ↑
10 This islet lies in the channel between
Maui and Kahoolawe, its surface but
a few feet above the water. ↑
11 Better known now as Maalaea, the
western landing for central Maui. ↑
12 Na-maka-a-hua, so divided,
becomes “the eyes of Hua.” ↑
13 Known generally as Olowalu,
adjacent to Lahaina on the south. ↑
14This is a familiar plot in several
Hawaiian legends, the origin of
which may be traced to the story of
Paao. ↑
15 This portion of the story is largely an
adaption from the legend of
Hamanalau, while the next section,
relating to Haupu, belongs to that of
Kana, in preceding volume, p. 448, but
with a new ending. ↑
16 An ancient proverb referring to an
early king whose wickedness won
him the detestation of his people, who
therefore let his body lie where he fell
that his bones bleached in the sun and
rattled in the wind. ↑
17 Pa’upa’u, intensive of pa’u, to cease;
to break off, or make an end of. ↑

You might also like