SE 433333 Software Testing Quality Assurance Dennis Mumaugh

  • Slides: 94
Download presentation
SE 433/333 Software Testing & Quality Assurance Dennis Mumaugh, Instructor dmumaugh@depaul. edu Office: CDM,

SE 433/333 Software Testing & Quality Assurance Dennis Mumaugh, Instructor dmumaugh@depaul. edu Office: CDM, Room 428 Office Hours: Tuesday, 4: 00 – 5: 30 April 25, 2017 SE 433: Lecture 5 1 of 94

Administrivia § Comments and Feedback § Grading: have not been assigned a grader, so

Administrivia § Comments and Feedback § Grading: have not been assigned a grader, so I get to do it myself. Working. § Midterm Examination this week [April 27 -May 1] Ø Ø Will use the Desire 2 Learn System (https: //d 2 l. depaul. edu/) Using Desire 2 Learn [See note]. » Details » Things to avoid April 25, 2017 SE 433: Lecture 5 2 of 94

SE 433 – Class 5 Topic: Black Box Testing Part 2, JUnit & Ant

SE 433 – Class 5 Topic: Black Box Testing Part 2, JUnit & Ant Reading: Ø Ø Ø Pezze and Young: Chapter 10 JUnit documentation: http: //junit. org Ant documentation: http: //ant. apache. org Ant introductory tutorial: http: //www. vogella. com/tutorials/Apache. Ant/article. html An example of using JUnit with Ant: JUnit 3. zip in D 2 L Articles on the Class Page and Reading List April 25, 2017 SE 433: Lecture 5 3 of 94

Assignment 6 Using JUnit and Ant Due Date: May 4, 2017, Objective § The

Assignment 6 Using JUnit and Ant Due Date: May 4, 2017, Objective § The objective of this assignment is to run JUnit tests using Ant. Requirements § Install standalone JUnit and Ant. § Write an Ant build file, build. xml, to compile and run the JUnit tests you have developed in Assignment 3 & 4. You should define a target named test. All that accomplishes all the tasks above. April 25, 2017 SE 433: Lecture 5 4 of 94

Assignment 7 Part 2: Test Case Implementation Due Date: May 11, 2017 § The

Assignment 7 Part 2: Test Case Implementation Due Date: May 11, 2017 § The objective of this assignment is to Ø design unit test suites using black-box techniques, Ø implementing the test suites using JUnit, and Ø run the test suites using Ant. § The binary code of both programs under test is provided in a zip file named classes. zip. § Unzip this file, you will find a directory named classes, that contains the compiled byte code of programs under test. § The programs match the descriptions given in the assignment. § However, the implementations may contain defects. You must include the classes directory in your classpath to run or test the programs. April 25, 2017 SE 433: Lecture 5 5 of 94

Thought for the Day “You must be a constructive schizophrenic. Be clear about the

Thought for the Day “You must be a constructive schizophrenic. Be clear about the difference between your role as a programmer and as a tester. The tester in you must be suspicious, uncompromising, hostile, and compulsively obsessed with destroying, utterly destroying, the programmer’s software. The tester in you is your Mr. Hyde – your Incredible Hulk. He must exercise what Gruenberger calls ‘low cunning. ” – Boris Beizer April 25, 2017 SE 433: Lecture 5 6 of 94

Black-box Testing April 25, 2017 SE 433: Lecture 5 7 of 94

Black-box Testing April 25, 2017 SE 433: Lecture 5 7 of 94

Black Box Testing § Testing software against a specification of its external behavior without

Black Box Testing § Testing software against a specification of its external behavior without knowledge of internal implementation details Ø Ø Can be applied to software “units” (e. g. , classes) or to entire programs External behavior is defined in API docs, Functional specs, Requirements specs, etc. § Because black box testing purposely disregards the program's control structure, attention is focused primarily on the information domain (i. e. , data that goes in, data that comes out) § The Goal: Derive sets of input conditions (test cases) that fully exercise the external functionality April 25, 2017 SE 433: Lecture 5 8 of 94

Black-box Testing Categories § § § § Incorrect or missing functions Interface errors Usability

Black-box Testing Categories § § § § Incorrect or missing functions Interface errors Usability problems Concurrency and timing errors Errors in data structures or external data base access Behavior or performance errors Initialization and termination errors § Unlike white box testing, black box testing tends to be applied later in the development process April 25, 2017 SE 433: Lecture 5 9 of 94

Questions answered by Black-box Testing § § § § How is functional validity tested?

Questions answered by Black-box Testing § § § § How is functional validity tested? How are system behavior and performance tested? What classes of input will make good test cases? Is the system particularly sensitive to certain input values? How are the boundary values of a data class isolated? What data rates and data volume can the system tolerate? What effect will specific combinations of data have on system operation? April 25, 2017 SE 433: Lecture 5 10 of 94

The Information Domain: inputs and outputs § Inputs Ø Ø Ø Individual input values

The Information Domain: inputs and outputs § Inputs Ø Ø Ø Individual input values » Try many different values for each individual input Combinations of inputs » Individual inputs are not independent from each other » Programs process multiple input values together, not just one at a time » Try many different combinations of inputs in order to achieve good coverage of the input domain Ordering and Timing of inputs » In addition to the particular combination of input values chosen, the ordering and timing of the inputs can also make a difference April 25, 2017 SE 433: Lecture 5 11 of 94

The Information Domain: inputs and outputs § Defining the input domain Ø Ø Boolean

The Information Domain: inputs and outputs § Defining the input domain Ø Ø Boolean value » T or F Numeric value in a particular range » -99 <= N <= 99 » Integer, Floating point » Non-negative One of a fixed set of enumerated values » {Jan, Feb, Mar, …} » {Visa, Master. Card, Discover, …} Formatted strings » Phone numbers » File names » URLs » Credit card numbers » Regular expressions April 25, 2017 SE 433: Lecture 5 12 of 94

Black Box Testing Equivalence classes April 25, 2017 SE 433: Lecture 5 13 of

Black Box Testing Equivalence classes April 25, 2017 SE 433: Lecture 5 13 of 94

Equivalence Partitioning § A black-box testing method that divides the input domain of a

Equivalence Partitioning § A black-box testing method that divides the input domain of a program into classes of data from which test cases are derived § An ideal test case single-handedly uncovers a complete class of errors, thereby reducing the total number of test cases that must be developed § Test case design is based on an evaluation of equivalence classes for an input condition § An equivalence class represents a set of valid or invalid states for input conditions § From each equivalence class, test cases are selected so that the largest number of attributes of an equivalence class are exercised at once April 25, 2017 SE 433: Lecture 5 14 of 94

Equivalence Partitioning § Typically the universe of all possible test cases is so large

Equivalence Partitioning § Typically the universe of all possible test cases is so large that you cannot try them all § You have to select a relatively small number of test cases to actually run § Which test cases should you choose? § Equivalence partitioning helps answer this question April 25, 2017 SE 433: Lecture 5 15 of 94

Equivalence Partitioning § Partition the test cases into "equivalence classes” § Each equivalence class

Equivalence Partitioning § Partition the test cases into "equivalence classes” § Each equivalence class contains a set of "equivalent" test cases § Two test cases are considered to be equivalent if we expect the program to process them both in the same way (i. e. , follow the same path through the code) § If you expect the program to process two test cases in the same way, only test one of them, thus reducing the number of test cases you have to run April 25, 2017 SE 433: Lecture 5 16 of 94

Equivalence Partitioning § First-level partitioning: Valid vs. Invalid test cases Valid April 25, 2017

Equivalence Partitioning § First-level partitioning: Valid vs. Invalid test cases Valid April 25, 2017 Invalid SE 433: Lecture 5 17 of 94

Equivalence Partitioning § Partition valid and invalid test cases into equivalence classes April 25,

Equivalence Partitioning § Partition valid and invalid test cases into equivalence classes April 25, 2017 SE 433: Lecture 5 18 of 94

Equivalence Partitioning § Create a test case for at least one value from each

Equivalence Partitioning § Create a test case for at least one value from each equivalence class April 25, 2017 SE 433: Lecture 5 19 of 94

Equivalence Partitioning § When designing test cases, you may use different definitions of “equivalence”,

Equivalence Partitioning § When designing test cases, you may use different definitions of “equivalence”, each of which will partition the test case space differently Ø Example: int Add(n 1, n 2, n 3, …) » Equivalence Definition 1: partition test cases by the number of inputs (1, 2, 3, etc. ) » Equivalence Definition 2: partition test cases by the number signs they contain (positive, negative, both) » Equivalence Definition 3: partition test cases by the magnitude of operands (large numbers, small numbers, both) » Etc. April 25, 2017 SE 433: Lecture 5 20 of 94

Equivalence Partitioning § When designing test cases, you may use different definitions of “equivalence”,

Equivalence Partitioning § When designing test cases, you may use different definitions of “equivalence”, each of which will partition the test case space differently Ø Example: string Fetch(URL) » Equivalence Definition 1: partition test cases by URL protocol (“http”, “https”, “ftp”, “file”, etc. ) » Equivalence Definition 2: partition test cases by type of file being retrieved (HTML, GIF, JPEG, Plain Text, etc. ) » Equivalence Definition 3: partition test cases by length of URL (very short, medium, long, very long, etc. ) » Same host » Etc. April 25, 2017 SE 433: Lecture 5 21 of 94

Equivalence Partitioning § Test multiple values in each equivalence class. Often you’re not sure

Equivalence Partitioning § Test multiple values in each equivalence class. Often you’re not sure if you have defined the equivalence classes correctly or completely, and testing multiple values in each class is more thorough than relying on a single value. April 25, 2017 SE 433: Lecture 5 22 of 94

Guidelines for Defining Equivalence Classes § If an input condition specifies a range, one

Guidelines for Defining Equivalence Classes § If an input condition specifies a range, one valid and two invalid equivalence classes are defined Ø Input range: 1 – 10 Eq classes: {1. . 10}, {x < 1}, {x > 10} § If an input condition requires a specific value, one valid and two invalid equivalence classes are defined Ø Input value: 250 Eq classes: {250}, {x < 250}, {x > 250} § If an input condition specifies a member of a set, one valid and one invalid equivalence class are defined Ø Input set: {-2. 5, 7. 3, 8. 4} Eq classes: {-2. 5, 7. 3, 8. 4}, {any other x} § If an input condition is a Boolean value, one valid and one invalid class are define Ø Input: {true condition} Eq classes: {true condition}, {false condition} April 25, 2017 SE 433: Lecture 5 23 of 94

Equivalence Partitioning - examples Input Valid Equivalence Classes Invalid Equivalence Classes A integer N

Equivalence Partitioning - examples Input Valid Equivalence Classes Invalid Equivalence Classes A integer N such that: -99 <= N <= 99 ? ? Phone Number Area code: [200, 999] Prefix: (200, 999] Suffix: Any 4 digits ? ? April 25, 2017 SE 433: Lecture 5 24 of 94

Equivalence Partitioning - examples Input Valid Equivalence Classes A integer N such that: -99

Equivalence Partitioning - examples Input Valid Equivalence Classes A integer N such that: -99 <= N <= 99 [-99, -10] [-9, -1] 0 [1, 9] [10, 99] Phone Number Area code: [200, 999] Prefix: (200, 999] Suffix: Any 4 digits April 25, 2017 Invalid Equivalence Classes ? ? SE 433: Lecture 5 ? 25 of 94

Equivalence Partitioning - examples Input Valid Equivalence Classes Invalid Equivalence Classes A integer N

Equivalence Partitioning - examples Input Valid Equivalence Classes Invalid Equivalence Classes A integer N such that: -99 <= N <= 99 [-99, -10] [-9, -1] 0 [1, 9] [10, 99] < -99 > 99 Malformed numbers {12 -, 1 -2 -3, …} Non-numeric strings {junk, 1 E 2, $13} Empty value Phone Number Area code: [200, 999] Prefix: (200, 999] Suffix: Any 4 digits April 25, 2017 ? SE 433: Lecture 5 ? 26 of 94

Equivalence Partitioning - examples Input Valid Equivalence Classes Invalid Equivalence Classes A integer N

Equivalence Partitioning - examples Input Valid Equivalence Classes Invalid Equivalence Classes A integer N such that: -99 <= N <= 99 [-99, -10] [-9, -1] 0 [1, 9] [10, 99] < -99 > 99 Malformed numbers {12 -, 1 -2 -3, …} Non-numeric strings {junk, 1 E 2, $13} Empty value Phone Number Area code: [200, 999] Prefix: (200, 999] Suffix: Any 4 digits 555 -5555 (555)555 -5555 200 <= Area code <= 999 200 < Prefix <= 999 April 25, 2017 SE 433: Lecture 5 ? 27 of 94

Equivalence Partitioning - examples Input Valid Equivalence Classes Invalid Equivalence Classes A integer N

Equivalence Partitioning - examples Input Valid Equivalence Classes Invalid Equivalence Classes A integer N such that: -99 <= N <= 99 [-99, -10] [-9, -1] 0 [1, 9] [10, 99] < -99 > 99 Malformed numbers {12 -, 1 -2 -3, …} Non-numeric strings {junk, 1 E 2, $13} Empty value Phone Number Area code: [200, 999] Prefix: (200, 999] Suffix: Any 4 digits 555 -5555 (555)555 -5555 200 <= Area code <= 999 200 < Prefix <= 999 Invalid format 5555555, (555)5555, etc. . Area code < 200 or > 999 Area code with non-numeric characters Similar for Prefix and Suffix April 25, 2017 SE 433: Lecture 5 28 of 94

Boundary Value Analysis § A greater number of errors occur at the boundaries of

Boundary Value Analysis § A greater number of errors occur at the boundaries of the input domain rather than in the "center" § Boundary value analysis is a test case design method that complements equivalence partitioning Ø It selects test cases at the edges of a class Ø It derives test cases from both the input domain and output domain April 25, 2017 SE 433: Lecture 5 29 of 94

Guidelines for Boundary Value Analysis 1. If an input condition specifies a range bounded

Guidelines for Boundary Value Analysis 1. If an input condition specifies a range bounded by values a and b, test cases should be designed with values a and b as well as values just above and just below a and b 2. If an input condition specifies a number of values, test case should be developed that exercise the minimum and maximum numbers. Values just above and just below the minimum and maximum are also tested § Apply guidelines 1 and 2 to output conditions; produce output that reflects the minimum and the maximum values expected; also test the values just below and just above § If internal program data structures have prescribed boundaries (e. g. , an array), design a test case to exercise the data structure at its minimum and maximum boundaries April 25, 2017 SE 433: Lecture 5 30 of 94

Boundary Value Analysis § When choosing values from an equivalence class to test, use

Boundary Value Analysis § When choosing values from an equivalence class to test, use the values that are most likely to cause the program to fail § Errors tend to occur at the boundaries of equivalence classes rather than at the "center" Ø If (200 < area. Code && area. Code < 999) { // valid area code } Ø Wrong! Ø If (200 <= area. Code && area. Code <= 999) { // valid area code } Ø Testing area codes 200 and 999 would catch this error, but a center value like 770 would not § In addition to testing center values, we should also test boundary values Ø Right on a boundary Ø Very close to a boundary on either side April 25, 2017 SE 433: Lecture 5 31 of 94

Boundary Value Analysis § Create test cases to test boundaries of equivalence classes April

Boundary Value Analysis § Create test cases to test boundaries of equivalence classes April 25, 2017 SE 433: Lecture 5 32 of 94

Boundary Value Analysis - examples Input Boundary Cases A number N such that: -99

Boundary Value Analysis - examples Input Boundary Cases A number N such that: -99 <= N <= 99 ? ? Phone Number Area code: [200. . 999] Prefix: [200. . 999] Suffix: Any 4 digits April 25, 2017 SE 433: Lecture 5 33 of 94

Boundary Value Analysis - examples Input Boundary Cases A number N such that: -99

Boundary Value Analysis - examples Input Boundary Cases A number N such that: -99 <= N <= 99 -100, -99, -98 -10, -9 -1, 0, 1 9, 10 98, 99, 100 Phone Number Area code: [200. . 999] Prefix: [200. . 999] Suffix: Any 4 digits April 25, 2017 ? SE 433: Lecture 5 34 of 94

Boundary Value Analysis - examples Input Boundary Cases A number N such that: -99

Boundary Value Analysis - examples Input Boundary Cases A number N such that: -99 <= N <= 99 -100, -99, -98 -10, -9 -1, 0, 1 9, 10 98, 99, 100 Phone Number Area code: [200. . 999] Prefix: [200. . 999] Suffix: Any 4 digits Area code: 199, 200, 201 Area code: 998, 999, 1000 Prefix: 200, 199, 198 Prefix: 998, 999, 1000 Suffix: 3 digits, 5 digits April 25, 2017 SE 433: Lecture 5 35 of 94

Boundary Value Analysis - examples § Numeric values are often entered as strings which

Boundary Value Analysis - examples § Numeric values are often entered as strings which are then converted to numbers internally [int x = atoi(str); ] § This conversion requires the program to distinguish between digits and non-digits § A boundary case to consider: Will the program accept / and : as digits? Char ASCII April 25, 2017 / 0 1 2 3 4 5 6 7 8 9 : 47 48 49 50 51 52 53 54 55 56 57 58 SE 433: Lecture 5 36 of 94

Mainstream usage testing § Don't get so wrapped up in testing boundary cases that

Mainstream usage testing § Don't get so wrapped up in testing boundary cases that you neglect to test "normal" input values Ø Values that users would typically enter during mainstream usage April 25, 2017 SE 433: Lecture 5 37 of 94

General Testing April 25, 2017 SE 433: Lecture 5 38 of 94

General Testing April 25, 2017 SE 433: Lecture 5 38 of 94

Testing for race conditions and other timing dependencies § Many systems perform multiple concurrent

Testing for race conditions and other timing dependencies § Many systems perform multiple concurrent activities Ø Operating systems manage concurrent programs, interrupts, etc. Ø Servers service many clients simultaneously Ø Applications let users perform multiple concurrent actions § Test a variety of different concurrency scenarios, focusing on activities that are likely to share resources (and therefore conflict) § "Race conditions" are bugs that occur only when concurrent activities interleave in particular ways, thus making them difficult to reproduce § Test on hardware of various speeds to ensure that your system works well on both slower and faster machines April 25, 2017 SE 433: Lecture 5 39 of 94

Performance Testing § Measure the system's performance Ø Ø Ø Running times of various

Performance Testing § Measure the system's performance Ø Ø Ø Running times of various tasks Memory usage, including memory leaks Network usage (Does it consume too much bandwidth? Does it open too many connections? ) Disk usage (Is the disk footprint reasonable? Does it clean up temporary files properly? ) Process/thread priorities (Does it play well with other applications, or does it hog the whole machine? ) April 25, 2017 SE 433: Lecture 5 40 of 94

Limit Testing § Test the system at the limits of normal use § Test

Limit Testing § Test the system at the limits of normal use § Test every limit on the program's behavior defined in the requirements Ø Ø Ø Maximum number of concurrent users or connections Maximum number of open files Maximum request size Maximum file size Etc. § What happens when you go slightly beyond the specified limits? Ø Does the system's performance degrade dramatically, or gracefully? April 25, 2017 SE 433: Lecture 5 41 of 94

Stress Testing § Test the system under extreme conditions (i. e. , beyond the

Stress Testing § Test the system under extreme conditions (i. e. , beyond the limits of normal use) § Create test cases that demand resources in abnormal quantity, frequency, or volume Ø Ø Ø Low memory conditions Disk faults (read/write failures, full disk, file corruption, etc. ) Network faults Unusually high number of requests Unusually large requests or files Unusually high data rates (what happens if the network suddenly becomes ten times faster? ) § Even if the system doesn't need to work in such extreme conditions, stress testing is an excellent way to find bugs April 25, 2017 SE 433: Lecture 5 42 of 94

Security Testing § Any system that manages sensitive information or performs sensitive functions may

Security Testing § Any system that manages sensitive information or performs sensitive functions may become a target for intrusion (i. e. , hackers) § § How feasible is it to break into the system? Learn the techniques used by hackers Try whatever attacks you can think of Hire a security expert to break into the system § If somebody broke in, what damage could they do? § If an authorized user became disgruntled, what damage could they do? April 25, 2017 SE 433: Lecture 5 43 of 94

Usability Testing § Is the user interface intuitive, easy to use, organized, logical? §

Usability Testing § Is the user interface intuitive, easy to use, organized, logical? § Does it frustrate users? § Are common tasks simple to do? § Does it conform to platform-specific conventions? § Get real users to sit down and use the software to perform some tasks § Watch them performing the tasks, noting things that seem to give them trouble § Get their feedback on the user interface and any suggested improvements § Report bugs for any problems encountered April 25, 2017 SE 433: Lecture 5 44 of 94

Recovery Testing § Try turning the power off or otherwise crashing the program at

Recovery Testing § Try turning the power off or otherwise crashing the program at arbitrary points during its execution Ø Ø Ø Does the program come back up correctly when you restart it? Was the program’s persistent data corrupted (files, databases, etc. )? Was the extent of user data loss within acceptable limits? § Can the program recover if its configuration files have been corrupted or deleted? § What about hardware failures? Does the system need to keep working when its hardware fails? If so, verify that it does so. April 25, 2017 SE 433: Lecture 5 45 of 94

Configuration Testing § Test on all required hardware configurations Ø CPU, memory, disk, graphics

Configuration Testing § Test on all required hardware configurations Ø CPU, memory, disk, graphics card, network card, etc. § Test on all required operating systems and versions thereof Ø Virtualization technologies such as VMWare and Virtual PC are very helpful for this § Test as many Hardware/OS combinations as you can § Test installation programs and procedures on all relevant configurations April 25, 2017 SE 433: Lecture 5 46 of 94

Compatibility Testing § Test to make sure the program is compatible with other programs

Compatibility Testing § Test to make sure the program is compatible with other programs it is supposed to work with Ø Ø Ø Ex: Can Word 12. 0 load files created with Word 11. 0? Ex: "Save As… Word, Word Perfect, PDF, HTML, Plain Text" Ex: "This program is compatible with Internet Explorer and Firefox” § Test all compatibility requirements April 25, 2017 SE 433: Lecture 5 47 of 94

Documentation Testing § Test all instructions given in the documentation to ensure their completeness

Documentation Testing § Test all instructions given in the documentation to ensure their completeness and accuracy § For example, “How To. . . ” instructions are sometimes not updated to reflect changes in the user interface § Test user documentation on real users to ensure it is clear and complete April 25, 2017 SE 433: Lecture 5 48 of 94

 JUnit & Ant April 25, 2017 SE 433: Lecture 5 49 of 94

JUnit & Ant April 25, 2017 SE 433: Lecture 5 49 of 94

Stand Alone JUnit & Ant § Ant – a versatile Java build tool Ø

Stand Alone JUnit & Ant § Ant – a versatile Java build tool Ø Control and execute various tasks in development, testing, configuration, distribution, & installation. Ø Full introduction a little later § Run all the tasks independent from IDE Ø Command-line, terminal mode Ø Batch mode, continuous integration § Full range of configuration options April 25, 2017 SE 433: Lecture 5 50 of 94

Prerequisite: Install JDK § Install latest JDK 7 or 8 (Java SE Development Kit)

Prerequisite: Install JDK § Install latest JDK 7 or 8 (Java SE Development Kit) Minimum JDK 5 § Download from oracle. com or java. com Ø Run installer Ø Typical location on Windows, called Java_Home Ø C: Program FilesJavajdk 8_u 25 § Add a new environment variable: JAVA_HOME § Add to environment variable PATH: Java_Home/bin Ø April 25, 2017 SE 433: Lecture 5 51 of 94

Setting Environment Variables § On Windows Ø Control panel | System Ø Advanced System

Setting Environment Variables § On Windows Ø Control panel | System Ø Advanced System Settings | Environment Variables Ø New …/Edit … user variables § On Linux or Mac. OSX Ø Edit: . bash_profile or. profile Ø Example: (Mac. OSX) export JAVA_HOME=“/usr/libexec/java_home” April 25, 2017 SE 433: Lecture 5 52 of 94

Download & Install JUnit 4 § JUnit home page Ø http: //junit. org §

Download & Install JUnit 4 § JUnit home page Ø http: //junit. org § Download the latest JUnit 4. 12 from github § Download 2 jar files to Junit_Home Ø Ø junit-4. 12. jar hamcrest-core-1. 3. jar § Both jar files must be in your classpath when you run JUnit. § Add a new environment variable: JUNIT_HOME Ø Set to Junit_Home April 25, 2017 SE 433: Lecture 5 53 of 94

Download & Install Ant § Download the latest Ant 1. 9. 9 [10. 1

Download & Install Ant § Download the latest Ant 1. 9. 9 [10. 1 is also available] http: //ant. apache. org/ Unzip to a folder your local drive: Ant_Home Add a new environment variable ANT_HOME Ø Set to Ant_Home Add to environment variable PATH: Ø Ant_Home/bin For Apple OSX: How to install Apache Ant on Mac OS X – http: //www. mkyong. com/ant/how-to-apache-ant-on-mac-osx/ Ø § § April 25, 2017 SE 433: Lecture 5 54 of 94

An Introduction to Ant – A Java Build Tool April 25, 2017 SE 433:

An Introduction to Ant – A Java Build Tool April 25, 2017 SE 433: Lecture 5 55 of 94

What is Ant? § Ant – a versatile Java-based build tool Ø Control and

What is Ant? § Ant – a versatile Java-based build tool Ø Control and execute various tasks in development, testing, configuration, distribution, & installation. Ø Widely used in Java projects Ø Integrated with IDE, including Eclipse § Same objectives as make – a Unix/C-based build tool § Ant build files (configuration) are written in XML April 25, 2017 SE 433: Lecture 5 56 of 94

Automating the Build (C & make) § The goal is to automate the build

Automating the Build (C & make) § The goal is to automate the build process a. out: driver. o foo. o bar. o gcc driver. o foo. o bar. o driver. o: driver. c foo. h bar. h gcc -c driver. c foo. o: foo. c foo. h gcc -c foo. c bar. o: gcc -c bar. c a. out gcc driver. o foo. o bar. o foo. o driver. o gcc -c foo. c gcc -c driver. c foo. h driver. c April 25, 2017 bar. o gcc -c bar. h linux 3[1]% make gcc -c driver. c gcc -c foo. c gcc -c bar. c gcc driver. o foo. o bar. o linux 3[2]% bar. c SE 433: Lecture 5 57 of 94

Project Organization § The following example assumes that your workspace will be organized like

Project Organization § The following example assumes that your workspace will be organized like so … Project Directory build. xml src *. java April 25, 2017 bin *. class SE 433: Lecture 5 doc *. html 58 of 94

Anatomy of a Build File § Ant’s build files are written in XML Ø

Anatomy of a Build File § Ant’s build files are written in XML Ø Convention is to call the file build. xml § Each build file contains Ø Ø A project At least 1 target § Targets are composed of some number of tasks § Build files may also contain properties Ø Like macros in a make file § Comments are within <!-- --> blocks April 25, 2017 SE 433: Lecture 5 59 of 94

The Ant Build File § The default build file, build. xml § Each build

The Ant Build File § The default build file, build. xml § Each build file contains one project § The project contains one or more targets § A simple build file <project default="hello"> <target name="hello"> <echo message="Hello, World"/> </target> </project> April 25, 2017 SE 433: Lecture 5 60 of 94

The Ant Build File – Project § Each build file contains exactly one project

The Ant Build File – Project § Each build file contains exactly one project The root element § The project attributes name the name of the project. default the default target basedir the base directory of all relative paths. § Example: <project name=“My. Project” default=“build” basedir=“. ”> Ø April 25, 2017 SE 433: Lecture 5 61 of 94

Projects § The project tag is used to define the project you wish to

Projects § The project tag is used to define the project you wish to work with § Projects tags typically contain 3 attributes Ø Ø Ø name – a logical name for the project default – the default target to execute basedir – the base directory for which all operations are done relative to § Additionally, a description for the project can be specified from within the project tag April 25, 2017 SE 433: Lecture 5 62 of 94

Build File <project name="Sample Project" default="compile" basedir=". "> <description> A sample build file for

Build File <project name="Sample Project" default="compile" basedir=". "> <description> A sample build file for this project </description> </project> April 25, 2017 SE 433: Lecture 5 63 of 94

Targets § The target tag has the following required attribute name – the logical

Targets § The target tag has the following required attribute name – the logical name for a target § Targets may also have optional attributes such as Ø depends – a list of other target names for which this task is dependent upon, the specified task(s) get executed first Ø description – a description of what a target does § Like make files, targets in Ant can depend on some number of other targets Ø For example, we might have a target to create a jarfile, which first depends upon another target to compile the code § A build file may additionally specify a default target Ø April 25, 2017 SE 433: Lecture 5 64 of 94

The Ant Build File – Targets § Each project contains one or more targets

The Ant Build File – Targets § Each project contains one or more targets One must be the default target § Each target contains one or more tasks § Targets are basic modules in the build Ø April 25, 2017 SE 433: Lecture 5 65 of 94

The Ant Build File – Targets § Some attributes of targets name the name

The Ant Build File – Targets § Some attributes of targets name the name of the target. description a short description of this target depends a comma-separated list of names of targets on which this target depends. § Execute Ant targets Ø ant execute and complete the default target Ø ant target execute and complete the specified target April 25, 2017 SE 433: Lecture 5 66 of 94

The Ant Build File – Target Dependency § Dependencies among the targets can be

The Ant Build File – Target Dependency § Dependencies among the targets can be specified Ø A depends on B, means B must be completed before A § Ant automatically resolves the dependencies Ø Determines the order of the dependent targets to be completed Ø Invokes all the dependent tasks, Ø Skips targets that have already been completed April 25, 2017 SE 433: Lecture 5 67 of 94

The Ant Build File – Target Dependency § Examples: April 25, 2017 <target name="A"/>

The Ant Build File – Target Dependency § Examples: April 25, 2017 <target name="A"/> <target name="B" depends="A"/> <target name="C" depends="B"/> <target name="D" depends="C, B, A"/> SE 433: Lecture 5 68 of 94

The Ant Build File – Tasks § Each target consists of one or more

The Ant Build File – Tasks § Each target consists of one or more tasks § Tasks are the actual jobs to be performed Ø e. g. , javac, jar, junit, etc. § Ant provides a rich set of built-in tasks Ø Core tasks § Ant also supports user-defined tasks Ø Needs to be defined before they can be used April 25, 2017 SE 433: Lecture 5 69 of 94

Tasks § A task represents an action that needs execution § Tasks have a

Tasks § A task represents an action that needs execution § Tasks have a variable number of attributes which are task dependent § There a number of build-in tasks, most of which are things which you would typically do as part of a build process Ø Ø Ø Create a directory Compile java source code Run the javadoc tool over some files Create a jar file from a set of files Remove files/directories And many, many others… » For a full list see: http: //ant. apache. org/manual/coretasklist. html April 25, 2017 SE 433: Lecture 5 70 of 94

Ant Core Tasks (Pre-Defined) § § § javac Runs the Java Compiler java Runs

Ant Core Tasks (Pre-Defined) § § § javac Runs the Java Compiler java Runs the Java Virtual Machine jar (war) Create JAR files mkdir Makes a directory copy Copies files to specified location delete Deletes specified files April 25, 2017 SE 433: Lecture 5 71 of 94

The Ant Build File – Tasks § Examples: <target name="prepare" depends="init“ > <mkdir dir="${bin}"

The Ant Build File – Tasks § Examples: <target name="prepare" depends="init“ > <mkdir dir="${bin}" /> </target> <target name="build" depends=”prepare" > <javac srcdir="src" destdir="${bin}"> <include name="**/*. java" /> </javac> </target> April 25, 2017 SE 433: Lecture 5 72 of 94

The Ant Build File – Property Definitions § Properties are name-value pairs § The

The Ant Build File – Property Definitions § Properties are name-value pairs § The property element defines properties that can be used in the rest of the build file § An example: Ø Property definition <property name=“src” value=“/home/src”/> Ø Using defined property » ${src} can be used anywhere in the build file to denote /home/src April 25, 2017 SE 433: Lecture 5 73 of 94

The Ant Build File – Property Definitions § Properties can also be defined in

The Ant Build File – Property Definitions § Properties can also be defined in a separate properties file and imported to the build file <property file=“myproperties” /> In myproperties, you may define (Java properties format) src=/home/src § Ant provides access to all system properties Ø e. g. , ${user. home}, ${user. name} April 25, 2017 SE 433: Lecture 5 74 of 94

The Ant Build File – Path Structures § Define paths used in various tasks

The Ant Build File – Path Structures § Define paths used in various tasks § Example of setting CLASSPATH (used in javac, java, etc. . ): <classpath> <pathelement path="${classpath}"/> <pathelement location="lib/helper. jar"/> </classpath> April 25, 2017 SE 433: Lecture 5 75 of 94

Running Ant – Command Line § Simply cd into the directory with the build.

Running Ant – Command Line § Simply cd into the directory with the build. xml file and type ant to run the project default target § Or, type ant followed by the name of a target April 25, 2017 SE 433: Lecture 5 76 of 94

Running Ant on Command-Line § Type ant Ø Looks for the default build file

Running Ant on Command-Line § Type ant Ø Looks for the default build file build. xml in the current directory. § Type ant –f mybuildfile. xml to specify another build file. April 25, 2017 SE 433: Lecture 5 77 of 94

Use JUnit with Ant § Ant supports <junit> task § JUnit jar files must

Use JUnit with Ant § Ant supports <junit> task § JUnit jar files must be in the classpath when the task is executed § Two options: Ø Add jar files in the classpath in the ant build file. » For each task, <javac>, <junit> etc. . (examples later) Ø Copy the jar files into the directory ANT_HOMElib April 25, 2017 SE 433: Lecture 5 78 of 94

Running Ant – Eclipse § Eclipse comes with out of the box support for

Running Ant – Eclipse § Eclipse comes with out of the box support for Ant Ø No need to separately download and configure Ant § Eclipse provides an Ant view Ø Window Show View Ant § Simply drag and drop a build file into the Ant view, then double click the target to run April 25, 2017 SE 433: Lecture 5 79 of 94

An Example of Using JUnit and Ant See JUnit 3. zip April 25, 2017

An Example of Using JUnit and Ant See JUnit 3. zip April 25, 2017 SE 433: Lecture 5 80 of 94

The Example Program – The Class Under Test package edu. depaul. se 433; public

The Example Program – The Class Under Test package edu. depaul. se 433; public class Binary. Search { public static int search(int[] a, int x) { … } public static int checked. Search(int[] a, int x) { … } } April 25, 2017 SE 433: Lecture 5 81 of 94

The JUnit Test package edu. depaul. se 433; import org. junit. *; import static

The JUnit Test package edu. depaul. se 433; import org. junit. *; import static org. junit. Assert. *; import static edu. depaul. se 433. Binary. Search. *; public class Binary. Search. Test { @Test public void test. Search 1() { … } @Test public void test. Search 2() { … } April 25, 2017 SE 433: Lecture 5 82 of 94

The Test Suite @Test public void test. Checked. Search 1() { int[] a =

The Test Suite @Test public void test. Checked. Search 1() { int[] a = { 1, 3, 5, 7}; assert. True(checked. Search(a, 3) == 1); } @Test(expected=Illegal. Argument. Exception. class) public void test. Checked. Search 2() { checked. Search(null, 1); } @Test public void test. Checked. Search 3() { … } April 25, 2017 SE 433: Lecture 5 83 of 94

Running JUnit in Ant: Ant Build File: build. xml <project name="My. Project" default="test 1"

Running JUnit in Ant: Ant Build File: build. xml <project name="My. Project" default="test 1" basedir=". "> <description> Ant build file </description> <!-- set global properties for this build --> <property name="src" location="src"/> <property name="bin" location="bin"/> <property name="junit" location="/Users/jia/Java/JUnit/junit-4. 12"/> <target name="init"> <tstamp/> <!-- Create the time stamp --> <mkdir dir="${bin}"/> </target> April 25, 2017 SE 433: Lecture 5 84 of 94

Running JUnit in Ant: Ant Build File: build. xml <target name="compile" depends="init" description="compile the

Running JUnit in Ant: Ant Build File: build. xml <target name="compile" depends="init" description="compile the source " > <!-- Compile the java code from ${src} into ${bin} --> <javac includeantruntime="false" srcdir="${src}" destdir="${bin}" debug="on"> <classpath location="${junit}/junit-4. 12. jar"/> <classpath location="${junit}/hamcrest-core-1. 3. jar"/> </javac> </target> April 25, 2017 SE 433: Lecture 5 85 of 94

Running JUnit in Ant: Ant Build File: build. xml <target name="test 1" depends="compile"> <!--

Running JUnit in Ant: Ant Build File: build. xml <target name="test 1" depends="compile"> <!-- Run junit tests --> <junit printsummary="yes" fork="yes"> <classpath location="${bin}"/> <classpath location="${junit}/junit-4. 12. jar"/> <classpath location="${junit}/hamcrest-core-1. 3. jar"/> <formatter type="plain"/> <test name="edu. depaul. se 433. Binary. Search. Test"/> </junit> </target> </project> April 25, 2017 SE 433: Lecture 5 86 of 94

Run JUnit with Ant § At the command line ant ~/Courses/SE 433/Examples/JUnit 3$ ant

Run JUnit with Ant § At the command line ant ~/Courses/SE 433/Examples/JUnit 3$ ant Buildfile: /Users/jia/Courses/SE 433/Examples/JUnit 3/build. xml init: [mkdir] Created dir: /Users/jia/Courses/SE 433/Examples/JUnit 3/bin compile: [javac] Compiling 2 source files to /Users/jia/Courses/SE 433/Examples/JUnit 3/bin test 1: [junit] Running edu. depaul. se 433. Binary. Search. Test [junit] Tests run: 5, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 0. 012 sec BUILD SUCCESSFUL Total time: 1 second April 25, 2017 SE 433: Lecture 5 87 of 94

JUnit Report § TEST-edu. depaul. se 433. Binary. Search. Test. txt Testsuite: edu. depaul.

JUnit Report § TEST-edu. depaul. se 433. Binary. Search. Test. txt Testsuite: edu. depaul. se 433. Binary. Search. Tests run: 5, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 0. 012 sec Testcase: test. Checked. Search 1 took 0. 001 sec Testcase: test. Checked. Search 2 took 0 sec Testcase: test. Checked. Search 3 took 0 sec Testcase: test. Search 2 took 0 sec Testcase: test. Search 1 took 0 sec April 25, 2017 SE 433: Lecture 5 88 of 94

Running Ant in Eclipse § Download and unzip JUnit 3. zip to your workspace

Running Ant in Eclipse § Download and unzip JUnit 3. zip to your workspace § New Java Project: JUnit 3 Ø Ø April 25, 2017 build. xml in the project Open build. xml SE 433: Lecture 5 89 of 94

Running Ant in Eclipse § Right click on the target “test 1 [default]” Ø

Running Ant in Eclipse § Right click on the target “test 1 [default]” Ø Run as -> Ant Build § You can also run other targets in the build file April 25, 2017 SE 433: Lecture 5 90 of 94

Readings and References § JUnit documentation http: //junit. org Ant documentation Ø http: //ant.

Readings and References § JUnit documentation http: //junit. org Ant documentation Ø http: //ant. apache. org Using Apache Ant: Writing a Simple Buildfile Ø http: //ant. apache. org/manual/using. html Ant introductory tutorial Ø http: //www. vogella. com/tutorials/Apache. Ant/article. html Ø How to install Apache Ant on Mac OS X – http: //www. mkyong. com/ant/how-to-apache-ant-on-macos-x/ An example of using JUnit with Ant Ø JUnit 3. zip in D 2 L Ø § § April 25, 2017 SE 433: Lecture 5 91 of 94

Next Class Topic: Ø Combinatorial Testing, White Box Testing Part 1 Reading: Ø Pezze

Next Class Topic: Ø Combinatorial Testing, White Box Testing Part 1 Reading: Ø Pezze and Young, Chapters 5. 1 -5. 3, 11. 1, 11. 3, 12 Ø Articles on the Class Page Assignment 6 – Using JUnit and Ant Ø Due: May 4, 2017 Assignment 7 – Part 2: Test Case Implementation Ø Due: May 11, 2017 April 25, 2017 SE 433: Lecture 5 92 of 94

Midterm Examination “Nobody expects the Spanish Inquisition!” – Monty Python April 25, 2017 SE

Midterm Examination “Nobody expects the Spanish Inquisition!” – Monty Python April 25, 2017 SE 433: Lecture 5 93 of 94

Mid-term Examination § Midterm Examination will be on the Desire 2 Learn system starting

Mid-term Examination § Midterm Examination will be on the Desire 2 Learn system starting Thursday, April 27, through Monday, May 1 § See important information about Taking Quizzes On-line § On Desire 2 Learn Ø Login to the Desire 2 Learn System (https: //courses. depaul. edu/) Ø Take the Mid-term examination. Ø It will be made available Thursday, April 27, 2017. Ø You must take the exam by COB Monday, May 1, 2017. Ø Allow 3 hours (should take about one and a half hour if you are prepared); note: books or notes should not be used. § Midterm study guide posted on the class page and on D 2 L April 25, 2017 SE 433: Lecture 5 94 of 94