1. Trang chủ
  2. » Công Nghệ Thông Tin

The art of software testing second edition phần 9 potx

26 498 0

Đang tải... (xem toàn văn)

Tài liệu hạn chế xem trước, để xem đầy đủ mời bạn chọn Tải xuống

THÔNG TIN TÀI LIỆU

Thông tin cơ bản

Tiêu đề Extreme Testing
Tác giả Kent Beck, Erich Gamma
Trường học University of California, Berkeley
Chuyên ngành Software Testing
Thể loại Sách
Năm xuất bản 2023
Thành phố Berkeley
Định dạng
Số trang 26
Dung lượng 396,15 KB

Các công cụ chuyển đổi và chỉnh sửa cho tài liệu này

Nội dung

This case could have been broken out into two unittests, but one goal of software testing in general is to minimize thenumber of test cases while still adequately checking for error cond

Trang 1

eight test cases identified (Note: We are using a very simple example

to illustrate the basics of Extreme Testing In practice you would have

a much more detailed program specification that may include itemssuch as user-interface requirements and output verbiage As a result,the list of test cases would increase substantially.)

Test case 1 from Table 8.2 combines two test scenarios It checkswhether the input is a valid prime and how the application behaveswith a valid input value You may use any valid prime in this test.Appendix B provides a list of the prime numbers less than 1,000 thatcould be used

We also test two scenarios with test case 2: What happens when theinput value is equal to the upper bounds and when the input is not aprime number? This case could have been broken out into two unittests, but one goal of software testing in general is to minimize thenumber of test cases while still adequately checking for error condi-tions Test case 3 checks the lower boundary of valid inputs as well astesting for invalid primes The second part of the check is not neededbecause test case 2 handles this scenario However, it is included by

JUnit is a freely available open-source tool used to automate unit tests of Java applications in Extreme Programming environments The creators, Kent Beck and Erich Gamma, developed JUnit to support the significant unit testing that occurs in the Extreme Pro- gramming environment JUnit is very small, but very flexible and feature rich You can create individual tests or a suite of tests You can automatically generate reports detailing the errors.

Before using JUnit, or any testing suite, you must fully stand how to use it JUnit is powerful but only after you master its API However, whether or not you adopt an XP methodology,

under-JUnit is a useful tool to provide sanity checks for your own code Check out www.junit.org for more information and to download the test suite In addition, there is a wealth of information on XP and XT at this Website.

Trang 2

default because 0 is not a prime number Test cases 4 and 5 ensure thatthe inputs are within the defined range, which is greater than 0 andless than, or equal to, 1,000.

Case 6 tests whether the application properly handles characterinput values Because we are doing a calculation, it is obvious that theapplication should reject character datatypes The assumption withthis test case is that Java will handle the datatype check This applica-tion must handle the exception raised when an invalid datatype issupplied This test will ensure that the exception is thrown Last, tests

7 and 8 check for the correct number of input values; any numberother than 1 should fail

Test Driver and Application

Now that we have designed both test cases, we can create the testdriver class, check4PrimeTest Table 8.3 maps the JUnit methods in

check4PrimeTestto the test cases covered

Note that the testCheckPrime_false() method tests two tions because the boundary values are not prime numbers Therefore,

condi-we can check for boundary-value errors and for invalid primes withone test method Examining this method in detail will reveal that thetwo tests actually do occur within it Here is the complete JUnitmethod from the check4JavaTestclass listed in Appendix A

Table 8.3 Test Driver Methods

Trang 3

public void testCheckPrime_false(){

a Boolean datatype, or a function that returns a Boolean value If false

is returned, then the test is considered a success

The snippet also provides an example of a benefit of creating testcases and test harnesses first You may notice that the parameter in the assertFalse()methods is a method, check4prime.primeCheck(n).This method will reside in a class of the application Creating the testharness first forced us to think about the structure of the application

In some respects, the application is designed to support the test ness Here we will need a method to check whether the input is aprime number, so we included it in the application

har-With the test harness complete, application coding can begin.Based on the program specification, test cases, and the test harness,the resultant Java application will consist of a single class, check4Prime,with the following definition:

public class check4Prime {

public static void main (String [] args) public void checkArgs(String [] args) throws Exception public boolean primeCheck (int num)

}

Briefly, per Java requirements, the main() procedure provides theentry point into the application The checkArgs() method asserts

that the input value is a positive, n, where 0 ⭌ n ⬉ 1,000 The

primeCheck() procedure checks the input value against a calculatedlist of prime numbers We implemented the sieve of Eratosthenes toquickly calculate the prime numbers This approach is acceptablebecause of the small number of prime numbers involved

Trang 4

The testing aspect of Extreme Programming is termed ExtremeTesting It focuses on unit and acceptance tests You run unit testswhenever a change to the code base occurs The customer runs theacceptance tests at major release points.

Extreme Testing also requires you to create the test harness, based

on the program specification, before you start coding your tion In this manner, you design your application to pass the unit tests,thus increasing the probability that it will meet the specification

Trang 6

CHAPTER 9

Testing Internet Applications

Just a few years ago, based applications seemed to be the wave of the future; today, thewave has arrived onshore, and customers, employees, and businesspartners expect companies to have a Web presence

Internet-Generally, small to medium-size businesses have simple Web pagesthey use to tout their products and services Larger enterprises oftenbuild full-fledged e-commerce applications to sell their wares, fromcookies to cars and from consulting services to entire virtual compa-nies that exist only on the Internet

Internet applications are essentially client-server applications inwhich the client is a Web browser and the server is a Web or applica-tion server Although conceptually simple, the complexity of theseapplications varies wildly Some companies have applications built forbusiness-to-consumer uses such as banking services or retail stores,while others have business-to-business applications such as supplychain management Development and user presentation/user inter-face strategies vary for these different types of Websites, and, as youmight imagine, the testing approach varies for the different types ofsites as well

The goal of testing Internet-based applications is no different fromthat of traditional applications You need to uncover errors in theapplication before deploying it to the Internet And, given the com-plexity of these applications and the interdependency of the compo-nents, you likely will succeed in finding plenty of errors

The importance of rooting out the errors in an Internet tion cannot be understated As a result of the openness and accessi-

applica-193

Trang 7

bility of the Internet, competition in the business-to-consumer arena

is intense Thus, the Internet has created a buyer’s market for goodsand services Consumers have developed high expectations, and ifyour site does not load quickly, respond immediately, and provideintuitive navigation features, chances are that the user will findanother site with which to conduct business

It would seem that consumers have higher quality expectations forInternet applications than they do for shrink-wrapped applications.When people buy products in a box and install them on their comput-ers, as long as the quality is “average,” they will continue to use them.One reason for this behavior is that they have paid for the applicationand it must be a product they perceive as useful or desirable Even aless-than-satisfactory program can’t be corrected easily, so if the appli-cation at least satisfies the users’ basic needs, they likely will retain theprogram On the Internet, an average-quality application will likelycause your customer to use a competitor’s site Not only will the cus-tomer leave your site if it exhibits poor quality, your corporate imagebecomes tarnished as well After all, who feels comfortable buying a carfrom a company that cannot build a suitable Website? Like it or not,your Website has become the new first impression for business In gen-eral, consumers don’t pay to access your Website, so there is littleincentive to remain loyal in the face of mediocre Website design orperformance

This chapter covers some of the basics of testing Internet tions This subject is large and complex, and many references existthat explore its details However, you will find that the techniquesexplained in early chapters apply to Internet testing as well Never-theless, because there are, indeed, functional and design differencesbetween Web applications and conventional applications, we wanted

applica-to point out some of the particulars of Web-based application testing

Basic E-commerce Architecture

Before diving into testing Internet-based applications, we will vide an overview of the three-tier client-server (C/S) architecture

Trang 8

pro-used in a typical Internet-based e-commerce application ally, each tier is treated as a black box with well-defined interfaces.This model allows you to change the internals of each tier withoutworrying about breaking another tier Figure 9.1 illustrates each tierand the associated components used by most e-commerce sites.Although not an official tier in the architecture, the client side andits relevance are worth discussing Most of the access to your applica-tions occurs from a Web browser running on a computer, althoughmany devices, such as cell phones, refrigerators, pagers, and automo-biles, are being developed that can connect to the Internet Browsersvary dramatically in how they render content from a Website As

Conceptu-we discuss later in this chapter, testing for browser compatibility is one challenge associated with testing Internet applications Vendorsloosely follow published standards to help make browsers behaveconsistently, but they also build in proprietary enhancements thatcause inconsistent behavior The remainder of the clients employcustom applications that use the Internet as a pipeline to a particularsite In this scenario, the application mimics a standard client-serverapplication you might find on a company’s local area network

Figure 9.1 Typical architecture of an e-commerce site.

Clients

Internet

Firewall

Tier 1 Web Server

Tier 2 Business Logic

XYZ, Inc.

Tier 3 Data Stores

Laptop computer

IBM Compatible

Trang 9

The Web server represents the first tier in the three-tier ture and houses the Website The look and feel of an Internet appli-cation comes from the first tier Thus, another term for this tier is

architec-the Presentation tier or layer, so dubbed because it provides architec-the visual

content to the end user The Web server can use static HyperTextMarkup Language (HTML) pages or Common Gateway Interface(CGI) scripts to create dynamic HTML, but most likely it uses acombination of static and dynamic pages

Tier 2, or the Business layer, houses the application server Here

you run the software that models your business processes The lowing lists some of the functionality associated with the businesslayer:

Another term for Tier 3 is the Data layer This tier consists of a

data-base infrastructure to communicate with the second tier The face into the Data layer is defined by the data model, which describeshow you want to store data Sometimes several database servers make

inter-up this tier You typically tune database systems in this layer to dle the high transaction rates encountered in an e-commerce site Inaddition to a database server, some e-commerce sites may place anauthentication server in this layer Most often, you use an LDAP(Lightweight Directory Application Protocol) server for this function

han-Testing Challenges

You will face many challenges when designing and testing based applications due to the large number of elements you cannotcontrol and the number of interdependent components Adequately

Trang 10

Internet-testing your application requires that you make some assumptionsabout the environment that your customers use and how they use thesite.

An Internet-based application has many failure points that youshould consider when designing a testing approach The followinglist provides some examples of the challenges associated with testingInternet-based applications:

• Large and varied user base The users of your Website possess

different skill sets, employ a variety of browsers, and usedifferent operating systems or devices You can also expect your customers to access your Website using a wide range ofconnection speeds Not everyone has T1 or broadband Internet access

• Business environment If you operate an e-commerce site, then

you must consider issues such as calculating taxes, determiningshipping costs, completing financial transactions, and trackingcustomer profiles

• Locales Users may reside in other countries, in which case you

will have internationalization issues such as language translation,time zone considerations, and currency conversion

• Testing environments To properly test your application, you will

need to duplicate the production environment This means you should use Web servers, application servers, and databaseservers that are identical to the production equipment For themost accurate testing results, the network infrastructure willhave to be duplicated as well This includes routers, switches,and firewalls

• Security Because your site is open to the world, you must

protect it from hackers They can bring your Website to agrinding halt with denial-of-service (DoS) attacks or rip offyour customers’ credit card information

Even from this list, which could be expanded considerably as weinclude viewpoints from a wide variety of developers and businesses,you can see that configuring a testing environment provides one of

Trang 11

the most challenging aspects of e-commerce development Testingapplications that process financial transactions requires the most effortand expense You must replicate all the components, both hardwareand software, used for the application to produce valid test results.Configuring such an environment is a costly endeavor You willincur not only equipment costs, but labor costs as well Most compa-nies fail to include these expenses when creating a budget for theirapplications Those that do include it generally underestimate thetime and monetary requirements In addition, the testing environ-ment needs a maintenance plan to support application upgradeefforts.

Another significant testing challenge you face is testing browsercompatibility There are several different browsers on the markettoday, and each behaves differently Although standards exist forbrowser operation, most vendors enhance their browsers to try andattract a loyal user base Unfortunately, this causes the browsers tooperate in a nonstandard way We cover this topic in greater detaillater in this chapter

Although many challenges exist when testing Internet-basedapplications, you should narrow your testing efforts to specific areas.Table 9.1 identifies some of the most important testing areas that canhelp ensure that users have a positive experience on your Website.Because the first impression is the most important impression,some of your testing will focus on usability and human-factor con-cerns This area concentrates on the look and feel of your applica-tion Items such as fonts, colors, and graphics play a major role inwhether users accept or reject your application

System performance also influences a customer’s first impression

As mentioned earlier, Internet users want instant gratification Theywill not wait long for pages to load or transactions to complete Lit-erally, a few seconds’ delay can cause your customer to try anothersite Poor performance may also cause customers to doubt the reli-ability of your site Therefore, you should set performance goals anddesign tests that reveal problems that cause your site to miss the goals.Users demand that the transaction occur rapidly and accuratelywhen purchasing products or services from your site They do not,

Trang 12

and should not, tolerate inaccurate billings or shipping errors ably worse than losing a customer is finding yourself liable for morethan the transaction amount if your application does not processfinancial transactions correctly.

Prob-Your application will likely collect data to complete tasks such aspurchases or e-mail registrations Therefore, you should ensure thatthe data you collect are valid For example, make sure that phonenumbers, ID numbers, currencies, e-mail addresses, and credit card

Table 9.1 Examples of Presentation, Business, and Data Tier Testing

• Ensure fonts are the • Check for proper • Ensure database same across browsers calculation of sales tax operations meet

and shipping charges performance goals.

• Check to make sure • Ensure documented • Verify data are all links point to performance rates are stored correctly valid files or Websites met for response times and accurately.

• Check graphics to and throughput rates • Verify that you can ensure they are the • Verify that transactions recover using correct resolution complete properly current backups and size • Ensure failed • Test failover or

• Spell-check each page transactions roll back redundancy

• Allow a copy editor correctly operations.

to check grammar • Ensure data are and style collected correctly.

• Check cursor

positioning when page loads to ensure

it is in the correct text box.

• Check to ensure

default button is selected when the page loads.

Trang 13

numbers are the correct length and are properly formatted In tion, you should check the integrity of your data Localization issuescan easily cause data corruption via truncation due to character-setissues.

addi-In the addi-Internet environment, it is critical to keep the Website able for customer use This requires that you develop and imple-ment maintenance guidelines for all the supporting applications andservers Items such as the Web server and RDBMS require a highlevel of management You must monitor logs, system resources, andbackups to ensure that these critical items do not fail As described inChapter 6, you want to maximize the mean time between failures(MTBF) and minimize the mean time to recovery (MTTR) for thesesystems

avail-Finally, network connectivity provides another area in which tofocus your testing efforts At some point, you can count on networkconnectivity going down The source of the failure might be theInternet itself, your service provider, or your internal network.Therefore, you need to create contingency plans for your applicationand infrastructure to respond gracefully when an outage occurs.Keeping with the theme of testing, you should design your tests tobreak your contingency plans

Testing Strategies

Developing a testing strategy for Internet-based applications requires

a solid understanding of each of the hardware and software nents that make up the application As is critical to successful testing

compo-of standard applications, a specification document is needed todescribe the expected functionality and performance of your Web-site Without this document, you cannot design the appropriate tests.You need to test components developed internally and those pur-chased from a third party For the components developed in-houseyou should employ the tactics presented in earlier chapters Thisincludes creating unit/module tests and performing code reviews

Ngày đăng: 09/08/2014, 16:20

TỪ KHÓA LIÊN QUAN