Introduction to Software Testing(2nd edition)Chapter 3Test .ppt
《Introduction to Software Testing(2nd edition)Chapter 3Test .ppt》由会员分享,可在线阅读,更多相关《Introduction to Software Testing(2nd edition)Chapter 3Test .ppt(29页珍藏版)》请在麦多课文档分享上搜索。
1、Introduction to Software Testing (2nd edition) Chapter 3 Test Automation,Paul Ammann & Jeff Offutthttp:/www.cs.gmu.edu/offutt/softwaretest/,Updated February 2016,What is Test Automation?,Reduces cost Reduces human error Reduces variance in test quality from different individuals Significantly reduce
2、s the cost of regression testing,Introduction to Software Testing, Edition 2 (Ch 3), Ammann & Offutt,2,The use of software to control the execution of tests, the comparison of actual outcomes to predicted outcomes, the setting up of test preconditions, and other test control and test reporting funct
3、ions,Software Testability (3.1),Plainly speaking how hard it is to find faults in the software Testability is dominated by two practical problems How to provide the test values to the software How to observe the results of test execution,Introduction to Software Testing, Edition 2 (Ch 3), Ammann & O
4、ffutt,3,The degree to which a system or component facilitates the establishment of test criteria and the performance of tests to determine whether those criteria have been met,Observability and Controllability,ObservabilitySoftware that affects hardware devices, databases, or remote files have low o
5、bservability ControllabilityEasy to control software with inputs from keyboards Inputs from hardware sensors or distributed software is harderData abstraction reduces controllability and observability,Introduction to Software Testing, Edition 2 (Ch 3), Ammann & Offutt,4,How easy it is to observe the
6、 behavior of a program in terms of its outputs, effects on the environment and other hardware and software components,How easy it is to provide a program with the needed inputs, in terms of values, operations, and behaviors,Components of a Test Case (3.2),A test case is a multipart artifact with a d
7、efinite structureTest case valuesExpected results A test oracle uses expected results to decide whether a test passed or failed,Introduction to Software Testing, Edition 2 (Ch 3), Ammann & Offutt,5,The result that will be produced by the test if the software behaves as expected,The input values need
8、ed to complete an execution of the software under test,Affecting Controllability and Observability,Prefix valuesPostfix valuesVerification Values : Values needed to see the results of the test case values Exit Values : Values or commands needed to terminate the program or otherwise return it to a st
9、able state,Introduction to Software Testing, Edition 2 (Ch 3), Ammann & Offutt,6,Any inputs that need to be sent to the software after the test case values are sent,Inputs necessary to put the software into the appropriate state to receive the test case values,Putting Tests Together,Test caseTest se
10、tExecutable test script,Introduction to Software Testing, Edition 2 (Ch 3), Ammann & Offutt,7,The test case values, prefix values, postfix values, and expected results necessary for a complete execution and evaluation of the software under test,A set of test cases,A test case that is prepared in a f
11、orm to be executed automatically on the test software and produce a report,Test Automation Framework (3.3),Introduction to Software Testing, Edition 2 (Ch 3), Ammann & Offutt,8,A set of assumptions, concepts, and tools that support test automation,Introduction to Software Testing, Edition 2 (Ch 3),
12、Ammann & Offutt,9,What is JUnit?,Open source Java testing framework used to write and run repeatable automated tests JUnit is open source (junit.org) A structure for writing test drivers JUnit features include: Assertions for testing expected results Test features for sharing common test data Test s
13、uites for easily organizing and running tests Graphical and textual test runners JUnit is widely used in industry JUnit can be used as stand alone Java programs (from the command line) or within an IDE such as Eclipse,Introduction to Software Testing, Edition 2 (Ch 3), Ammann & Offutt,10,JUnit Tests
14、,JUnit can be used to test an entire object part of an object a method or some interacting methods interaction between several objects It is primarily intended for unit and integration testing, not system testing Each test is embedded into one test method A test class contains one or more test metho
15、ds Test classes include : A collection of test methods Methods to set up the state before and update the state after each test and before and after all tests Get started at junit.org,Introduction to Software Testing, Edition 2 (Ch 3), Ammann & Offutt,11,Writing Tests for JUnit,Need to use the method
16、s of the junit.framework.assert class javadoc gives a complete description of its capabilities Each test method checks a condition (assertion) and reports to the test runner whether the test failed or succeeded The test runner uses the result to report to the user (in command line mode) or update th
17、e display (in an IDE) All of the methods return void A few representative methods of junit.framework.assert assertTrue (boolean) assertTrue (String, boolean) fail (String),Introduction to Software Testing, Edition 2 (Ch 3), Ammann & Offutt,12,JUnit Test Fixtures,A test fixture is the state of the te
18、st Objects and variables that are used by more than one test Initializations (prefix values) Reset values (postfix values) Different tests can use the objects without sharing the state Objects used in test fixtures should be declared as instance variables They should be initialized in a Before metho
19、d Can be deallocated or reset in an After method,Introduction to Software Testing, Edition 2 (Ch 3), Ammann & Offutt,13,Simple JUnit Example,public class Calc static public int add (int a, int b)return a + b; ,import org.junit.Test; import static org.junit.Assert.*; public class CalcTest Test public
20、 void testAdd()assertTrue (“Calc sum incorrect”, 5 = Calc.add (2, 3); ,Test values,Expected output,Printed if assert fails,Note: JUnit 4 syntax,Introduction to Software Testing, Edition 2 (Ch 3), Ammann & Offutt,14,Testing the Min Class,import java.util.*;public class Min /* Returns the mininum elem
21、ent in a list* param list Comparable list of elements to search* return the minimum element in the list* throws NullPointerException if list is null or* if any list elements are null* throws ClassCastException if list elements are not mutually comparable* throws IllegalArgumentException if list is e
22、mpty*/ ,public static T min (List list)if (list.size() = 0)throw new IllegalArgumentException (“Min.min“);Iterator itr = list.iterator();T result = itr.next();if (result = null) throw new NullPointerException (“Min.min“);while (itr.hasNext() / throws NPE, CCE as neededT comp = itr.next();if (pareTo
23、(result) 0)result = comp; return result; ,MinTest Class,Standard imports for all JUnit classes :,Introduction to Software Testing, Edition 2 (Ch 3), Ammann & Offutt,15,import static org.junit.Assert.*; import org.junit.*; import java.util.*;,Test fixture and pre-test setup method (prefix) :,Post tes
- 1.请仔细阅读文档,确保文档完整性,对于不预览、不比对内容而直接下载带来的问题本站不予受理。
- 2.下载的文档,不会出现我们的网址水印。
- 3、该文档所得收入(下载+内容+预览)归上传者、原创作者;如果您是本文档原作者,请点此认领!既往收益都归您。
下载文档到电脑,查找使用更方便
2000 积分 0人已下载
下载 | 加入VIP,交流精品资源 |
- 配套讲稿:
如PPT文件的首页显示word图标,表示该PPT已包含配套word讲稿。双击word图标可打开word文档。
- 特殊限制:
部分文档作品中含有的国旗、国徽等图片,仅作为作品整体效果示例展示,禁止商用。设计者仅对作品中独创性部分享有著作权。
- 关 键 词:
- INTRODUCTIONTOSOFTWARETESTING2NDEDITIONCHAPTER3TESTPPT

链接地址:http://www.mydoc123.com/p-376718.html