CSE 403 Lecture 16. Continuous Integration; Integration Testing. Reading:

Similar documents
3 Continuous Integration 3. Automated system finding bugs is better than people

JUnit Testing Patterns: Mocking and Doubles

Continuous Integration / Continuous Testing

Super Charge Your Continuous Integration Deployments. Nikola Gotsev April 26, 2016

CSE 403 Lecture 11. Static Code Analysis. Reading: IEEE Xplore, "Using Static Analysis to Find Bugs"

Integration and Testing. Uses slides from Lethbridge & Laganiere, 2001

Con. Continuous Integration

Chapter 11, Testing, Part 2: Integration and System Testing

The Art of Unit Testing

MOCKING TO FACILITATE UNIT TESTING. Abstract

CSE 403 Lecture 21. Refactoring and Code Maintenance. Reading: Code Complete, Ch. 24, by S. McConnell Refactoring, by Fowler/Beck/Brant/Opdyke

Testing. Topics. Types of Testing. Types of Testing

Chapter 11, Testing, Part 2: Integration and System Testing

Utilizing Fast Testing to Transform Java Development into an Agile, Quick Release, Low Risk Process

SECTION 2: Loop Reasoning & HW3 Setup

SECTION 2: Loop Reasoning & HW3 Setup

JUnit in EDA Introduction. 2 JUnit 4.3

Lecture 3: Processing Language Data, Git/GitHub. LING 1340/2340: Data Science for Linguists Na-Rae Han

SECTION 2: HW3 Setup.

JenkinsPipelineUnit. Test your Continuous Delivery Pipeline. Ozan Gunalp - Emmanuel Quincerot

Chapter01.fm Page 1 Monday, August 23, :52 PM. Part I of Change. The Mechanics. of Change

Object Oriented Software Design - I

Test all the things! Get productive with automated testing in Drupal 8. Sam Becker

Technology Background Development environment, Skeleton and Libraries

CPSC 491. Lecture 19 & 20: Source Code Version Control. VCS = Version Control Software SCM = Source Code Management

Lecturer: William W.Y. Hsu. Programming Languages

Quality-Driven Build Scripts for Java Applications. Duy (uu-eee) B. Vo Graduate Student San José State University Department of Computer Science

CSE 70 Final Exam Fall 2009

Philosophy of Unit Testing

Don t give up on mocking

CS 390 Software Engineering Lecture 3 Configuration Management

Technology Background Development environment, Skeleton and Libraries

Mock Objects and Distributed Testing

Chapter 11, Testing, Part 2: Integration and System Testing

Review Version Control Concepts

Software Development. Integrated Software Environment

Jenkins: A complete solution. From Continuous Integration to Continuous Delivery For HSBC

What is Software Architecture

Test Execution and Automation. CSCE Lecture 15-03/20/2018

Program Verification! Goals of this Lecture! Words from the Wise! Testing!

Building in Quality: The Beauty of Behavior Driven Development (BDD) Larry Apke - Agile Coach

Reducing the pain of Yocto development upgrades. Michael Brown NGM Firmware Lead Technologist Dell EMC Embedded Linux Conference 2017

Testing! The material for this lecture is drawn, in part, from! The Practice of Programming (Kernighan & Pike) Chapter 6!

Branching and Merging

Revision Control. How can 4. Slides #4 CMPT 276 Dr. B. Fraser. Local Topology Simplified. Git Basics. Revision Control:

Lecture 15 Software Testing

CMSC 132: OBJECT-ORIENTED PROGRAMMING II

ONAP Developer Typical Setup 2017 July ONAP Virtual Developers Event

What is version control? (discuss) Who has used version control? Favorite VCS? Uses of version control (read)

Testing & Debugging TB-1

FPLLL. Contributing. Martin R. Albrecht 2017/07/06

Testing! The material for this lecture is drawn, in part, from! The Practice of Programming (Kernighan & Pike) Chapter 6!

The COS 333 Project. Robert M. Dondero, Ph.D. Princeton University

Git Branching for Agile Teams

SECTION 1: CODE REASONING + VERSION CONTROL + ECLIPSE

Chapter 9. Software Testing

Chapter 10 :: Data Abstraction and Object Orientation

Benefits of the Build

Software Testing Strategies. Slides copyright 1996, 2001, 2005, 2009, 2014 by Roger S. Pressman. For non-profit educational use only

ECE 3574: Applied Software Design: Unit Testing using Catch. Chris Wyatt

Patterns Of Enterprise Application Architecture

B - Broken Track Page 1 of 8

Language alone won t pay your bills. Alan Franzoni - EP 2012 twitter: franzeur website:

Samba4 Status - April Andrew Tridgell Samba Team

CSE 390 Lecture 9. Version control and Subversion (svn)

CSE 143 Lecture 10. Recursion

CSE 403 Lecture 17. Usability Testing. Reading: Don't Make Me Think! A Common Sense Approach to Web Usability by S. Krug, Ch. 9-11

Unit testing basics & more...

Development Practice and Quality Assurance. Version Control. The first thing you should be told when you start a new job - Steve Freeman

Introduction: Manual Testing :

CSE 374 Programming Concepts & Tools. Hal Perkins Fall 2015 Lecture 15 Testing


A Strategic Approach to Web Application Security

Chapter 1 Getting Started

Lab Exercise Test First using JUnit

Software Evolution. Dr. James A. Bednar. With material from

Boot Camp. Dave Eckhardt Bruce Maggs

TESTING AND DEBUGGING

a brief introduction to creating quality software continuously Copyright 2011 Davisbase, LLC

Test-driven development

Improving Software Testability

SCAFFOLDING WITH JMOCK

GIT : BEST PRACTICES GUIDE BY ERIC PIDOUX DOWNLOAD EBOOK : GIT : BEST PRACTICES GUIDE BY ERIC PIDOUX PDF

Introduction to Software Engineering: Tools and Environments. Session 9. Oded Lachish

Refactoring Without Ropes

Java EE Architecture, Part Two. Java EE architecture, part two 1

Version Control. Second level Third level Fourth level Fifth level. - Software Development Project. January 17, 2018

Mock Objects and the Mockito Testing Framework Carl Veazey CSCI Friday, March 23, 12

Intro to Github. Jessica Young

Software configuration management

Lecture 01 & 02 Computer Programming

Linked Lists. References and objects

Git and GitHub. Dan Wysocki. February 12, Dan Wysocki Git and GitHub February 12, / 48

Inverting the Pyramid

Implementation Architecture

Creating User-Friendly Exploits

Programming Assignment IV Due Monday, November 8 (with an automatic extension until Friday, November 12, noon)

The Power of Unit Testing and it s impact on your business. Ashish Kumar Vice President, Engineering

Advanced Java Testing. What s next?

Programming with Haiku

Transcription:

CSE 403 Lecture 16 Continuous Integration; Integration Testing Reading: Continuous Integration (Fowler) The Art of Unit Testing, Ch. 1, 3, 4-5 (Osherove) Code Complete, Ch. 29 (McConnell) slides created by Marty Stepp http://www.cs.washington.edu/403/

Integration integration: Combining 2 or more software units often a subset of the overall project (!= system testing) Why do software engineers care about integration? new problems will inevitably surface many systems now together that have never been before if done poorly, all problems present themselves at once hard to diagnose, debug, fix cascade of interdependencies cannot find and solve problems one-at-a-time 2

Phased integration phased ("big-bang") integration: design, code, test, debug each class/unit/subsystem separately combine them all pray 3

Incremental integration incremental integration: develop a functional "skeleton" system (i.e. ZFR) design, code, test, debug a small new piece integrate this piece with the skeleton test/debug it before adding any other pieces 4

Benefits of incremental Benefits: Errors easier to isolate, find, fix reduces developer bug-fixing load System is always in a (relatively) working state good for customer relations, developer morale Drawbacks: May need to create "stub" versions of some features that have not yet been integrated 5

Top-down integration top-down integration: Start with outer UI layers and work inward must write (lots of) stub lower layers for UI to interact with allows postponing tough design/debugging decisions (bad?) 6

Bottom-up integration bottom-up integration: Start with low-level data/logic layers and work outward must write test drivers to run these layers won't discover high-level / UI design flaws until late 7

"Sandwich" integration "sandwich" integration: Connect top-level UI with crucial bottom-level classes add middle layers later as needed more practical than top-down or bottom-up? 8

Continuous Integration Pioneered by Martin Fowler; part of Extreme Programming Ten principles: maintain a single source repository automate the build make your build self-testing everyone commits to mainline every day every commit should build mainline on an integration machine keep the build fast test in a clone of the production environment make it easy for anyone to get the latest executable everyone can see what's happening automate deployment 9

Daily builds "Automate the build." daily build: Compile working executable on a daily basis allows you to test the quality of your integration so far helps morale; product "works every day"; visible progress best done automated or through an easy script quickly catches/exposes any bug that breaks the build Continuous Integration (CI) server: An external machine that automatically pulls down your latest repo code and fully builds all resources. If anything fails, contacts your team (e.g. by email). Ensures that the build is never broken for long. 10

Build from command line An Android project needs a build.xml to be used by Ant. This file allows your project to be compiled from the command line, making automated builds possible. <?xml version="1.0" encoding="utf-8"?> <project name="mainactivity" default="help"> <property file="ant.properties" /> <import file="${sdk.dir}/tools/ant/build.xml" /> <taskdef name="findbugs" classname="edu.umd.cs.findbugs.anttask.findbugstask"/> <target name="findbugs"> <findbugs home="${findbugs.home}" output="xml" outputfile="findbugs.xml" excludefilter="findbugs-exclude.xml"> <auxclasspath path="${android.jar}" /> <auxclasspath path="${rt.jar}" /> <auxclasspath path="libs\android-support-v4.jar" /> <class location="${out.dir}" /> </findbugs> </target> <taskdef resource="checkstyletask.properties" classpath="${basedir}/libs/checkstyle-5.6-all.jar"/> <checkstyle config="sun_checks.xml" failonviolation="false"> <fileset dir="src" includes="**/*.java"/> <formatter type="plain"/> <formatter type="xml" tofile="checkstyle-result.xml"/> </checkstyle> </project> 11

Automated tests "Make your build self-testing." automated tests: e.g. Tests that can be run from the command line on your project code at any time. can be unit tests, coverage, static analysis / style checking,... smoke test: A quick set of tests run on the daily build. NOT exhaustive; just sees whether code "smokes" (breaks) used (along with compilation) to make sure daily build runs 12

Daily commits "Everyone commits to the mainline every day." daily commit: Submit work to main repo at end of each day. Idea: Reduce merge conflicts; avoid later integration issues. This is the key to "continuous integration" of new code. Caution: Don't check in faulty code (does not compile, does not pass tests) just to maintain the daily commit practice. If your code is not ready to submit at end of day, either submit a coherent subset or be flexible about commit schedule. 13

Integration testing integration testing: Verifying software quality by testing two or more dependent software modules as a group. challenges: Combined units can fail in more places and in more complicated ways. How to test a partial system where not all parts exist? How to "rig" the behavior of unit A so as to produce a given behavior from unit B? 14

Stubs stub: A controllable replacement for an existing software unit to which your code under test has a dependency. useful for simulating difficult-to-control elements: network / internet database time/date-sensitive code files threads memory also useful when dealing with brittle legacy code/systems 15

Create a stub, step 1 Identify the external dependency. This is either a resource or a class/object. If it isn't an object, wrap it up into one. (Suppose that Class A depends on troublesome Class B.) 16

Create a stub, step 2 Extract the core functionality of the object into an interface. Create an InterfaceB based on B Change all of A's code to work with type InterfaceB, not B 17

Create a stub, step 3 Write a second "stub" class that also implements the interface, but returns pre-determined fake data. Now A's dependency on B is dodged and can be tested easily. Can focus on how well A integrates with B's external behavior. 18

Injecting a stub seams: Places to inject the stub so Class A will talk to it. at construction (not ideal) A aardvark = new A(new StubB()); through a getter/setter method (better) A apple = new A(...); aardvark.setresource(new StubB()); just before usage, as a parameter (also better) aardvark.methodthatusesb(new StubB()); You should not have to change A's code everywhere (beyond using your interface) in order to use your Stub B. (a "testable design") 19

"Mock" objects mock object: A fake object that decides whether a unit test has passed or failed by watching interactions between objects. useful for interaction testing (as opposed to state testing) 20

Stubs vs. mocks A stub gives out data that goes to the object/class under test. The unit test directly asserts against class under test, to make sure it gives the right result when fed this data. A mock waits to be called by the class under test (A). Maybe it has several methods it expects that A should call. It makes sure that it was contacted in exactly the right way. If A interacts with B the way it should, the test passes. 21

Mock object frameworks Stubs are often best created by hand/ide. Mocks are tedious to create manually. Mock object frameworks help with the process. android-mock, EasyMock, jmock (Java) FlexMock / Mocha (Ruby) SimpleTest / PHPUnit (PHP)... Frameworks provide the following: auto-generation of mock objects that implement a given interface logging of what calls are performed on the mock objects methods/primitives for declaring and asserting your expectations 22

A jmock mock object import org.jmock.integration.junit4.*; // Assumes that we are testing import org.jmock.*; // class A's calls on B. @RunWith(JMock.class) public class ClassATest { private Mockery mockery = new JUnit4Mockery(); // initialize jmock } @Test public void testacallsbproperly1() { // create mock object to mock InterfaceB final InterfaceB mockb = mockery.mock(interfaceb.class); } // construct object from class under test; attach to mock A aardvark = new A(...); aardvark.setresource(mockb); // declare expectations for how mock should be used mockery.checking(new Expectations() {{ oneof(mockb).method1("an expected parameter"); will(returnvalue(0.0)); oneof(mockb).method2(); }}); // execute code A under test; should lead to calls on mockb aardvark.methodthatusesb(); // assert that A behaved as expected mockery.assertissatisfied(); 23

jmock API jmock has a strange API based on "Hamcrest" testing syntax. Specifying objects and calls: oneof(mock), exactly(count).of(mock), atleast(count).of(mock), atmost(count).of(mock), between(min, max).of(mock) allowing(mock), never(mock) The above accept a mock object and return a descriptor that you can call methods on, as a way of saying that you demand that those methods be called by the class under test. atleast(3).of(mockb).method1(); "I expect that method1 will be called on mockb 3 times here." 24

Expected actions.will(action) actions: returnvalue(v), throwexception(e) values: equal(value), same(value), any(type), anull(type), anonnull(type), not(value), anyof(value1,..,valuen) oneof(mockb).method1(); will(returnvalue(anyof(1, 4, -3))); "I expect that method1 will be called on mockb once here, and that it will return either 1, 4, or -3." 25

Using stubs/mocks together Suppose a log analyzer reads from a web service. If the web fails to log an error, the analyzer must send email. How to test to ensure that this behavior is occurring? Set up a stub for the web service that intentionally fails. Set up a mock for the email service that checks to see whether the analyzer contacts it to send an email message. 26