Recent Changes - Search:

Software Engineering

This website demonstrates using wikis as teaching and learning tool.

The course instructor is also happy to share the teaching materials here with those who find it readable.

Software Testing - Part 1

A Software Engineering Lecture by Steven Choy

Lecture Overview:

In this lecture, we will start to learn Software Testing. You will learn the meaning and use of test cases, test stubs and test drivers. Testing typically proceeds from unit testing via integration testing to system testing. You will also learn the common techniques available in each of the three types of testing.

Reading: Chapter 11 of the textbook Testing


Software Testing Overview

What's your view on Testing?

  • Testing is dirty work?
  • Testing is boring?
  • Testing is non-technical?
  • Testing is tedious?
  • Testing is for those less-talented developers?

But the fact is

  • Testing is a creative, systematic kind of work
  • Highly talented people are required to work on testing
  • Highly skilled programmers develop innovative test tools and strategies (e.g. JUnit and Test-Driven Development)

What's our target for Testing?

So what qualities do we measure?

  • Correctness (Functional Requirements)
  • Reliability (Non-functional Requirements)
  • Robustness (the meaning of robust)
  • Security
  • Performance
  • Usability

Strategies for Improving Software Qualities

  • Detective Approach (Our Focus)
    • Find out the potential bugs and fix it
    • Testing & Debugging
  • Preventive Approach
    • Avoid the bug to come out
      • An well-established development methodologies such as design & code review, configuration management
      • Use well-practiced design such as design pattern
  • Recovery Approach
    • Admit it's impossible to test the system completely that there may be faults in the system
    • But even the system fails, it can recover itself at runtime without affecting the user

Test Development Lifecycle

How do you do the Testing?

Test Development Lifecycle

Testing Activities

  • Component Inspection
    • Discover fault by code review
    • Carried out during design/coding stage
  • Test Planning (Plan what to test)
    • What features to be tested
    • What features not to be tested
    • The Test Approach
    • The Test Deliverable
    • The Test Schedule and Resource Allocation
  • Usability Testing
    • Test users' understanding of the system
    • Usually performed during product prototype stage by client/end-user
  • Unit Testing
    • Focus testing on unit level (e.g. object & subsystem)
  • Integration Testing
    • Perform tests on a group of components/subsystems
  • System Testing
    • Functional Testing
    • Performance Testing
    • Pilot Testing
    • Acceptance Testing

Fault Handling Techniques

Quality Assurance encompasses Testing

Testing Vocabulary

  • Component
    • An object, groups of objects or subsystem that can be isolated for testing
  • Fault / Bug / Defect
    • A design or coding mistake that contributes to the failure of a component
  • Failure
    • Deviation of the observed behaviour from the specified/expected behaviour
  • Test Case
    • Detailed instructions (with a set of input data & expected results) on exercising a component with the purpose to detecting faults

Developing Test Case

  • We develop test case to exercise a component with the purpose of causing failures and detecting faults
  • A test case normally includes:
    • Name
    • Component/Feature to be tested
    • Detailed test procedures
    • Input Data
    • Pass/Fail Criteria, Expected Result

Unit Testing

Unit Testing Overview

  • Focus on components (i.e. objects/subsystem) testing, rather than the whole system
  • Responsible by developer (usually by the developer who actually write the component)
  • Why Unit Testing?
    • Reduce complexity of testing
    • Ease to locate faults/bugs in a specific component
  • Current Development Trend
    • Automated Unit Testing e.g. JUnit Framework
      • Encourage developers to write test
      • Make testing fun!

Test Stubs & Driver

  • Test Stub
    • A partial implementation of components on which the tested component depends
    • A stub consists of interfaces that are identical to the actual component but with simpler implementation (It can be as simple as a return statement)
  • Test Driver
    • Simulates the part of the system that controls (drives) the component under test
    • Passes in the test inputs to the component under test and displays the result

Test Stub & Driver in Action

  • If you are the developer of the Login component, how do you unit-test it?

Example of Login Component

class LoginComponent {

	public boolean login(String userId, String password) {
		DataAccessComponent dac = new DataAccessComponent();
		String originPassword = dac.getPassword(userId);
		if (password.equals(originPassword)) {
			return true;
		} else {
			return false;
		}
	}

}

Test Driver & Stub Samples

class TestDriver {

	public static void main(String[] args) {
		LoginComponent lc = new LoginComponent();
		boolean result = lc.login("tester", "1234");
		System.out.println("Login result: " + result);
	}

}

class DataAccessComponent {

	public String getPassword(String userId) {
		return "1234";
	}

}

Test Stub & Driver in Action

  • We develop a Test Driver to invoke the Login component
  • As the Data Access Component is not in place, we develop a Test Stub to emulate the function it provides (Only those functions that Login Component needs during testing)

Black-box Testing

  • Test how well the code meets the requirement
  • Know nothing about the internal logic of the component/module (Treat it as a Blackbox)
  • Focus on the input/output behaviour

White-box Testing

  • Performed to reveal the internal structure of a program
  • Covers every statement of the component (Each statement is executed once)
  • Derive test cases from the code
  • Types of white-box testing:
    • Statement Testing
    • Loop Testing
    • Path Testing
    • Branch Testing

FindMean(float Mean, FILE ScoreFile) {

	SumOfScores = 0.0;
	NumberOfScores = 0;
	Mean = 0;
 	Read(ScoreFile, Score);	/*Read in and sum the scores*/
	while (! EOF(ScoreFile) { 
		if ( Score > 0.0 ) {
			SumOfScores = SumOfScores + Score;
			NumberOfScores++;
		}
		Read(ScoreFile, Score);
	}
	/* Compute the mean and print the result */
	if (NumberOfScores > 0 ) { 
		Mean = SumOfScores/NumberOfScores;
		printf("The mean score is %f \n",  Mean);
	} else 
		printf("No scores found in file\n");

}

Constructing the Logic Flow Diagram

Finding the Test Cases

Comparison of White & Black-box Testing

  • White-box Testing:
    • Potentially infinite number of paths have to be tested
    • White-box testing often tests what is done, instead of what should be done
    • Cannot detect missing use cases
  • Black-box Testing:
    • Potential combinatorical explosion of test cases (valid & invalid data)
    • Often not clear whether the selected test cases uncover a particular error
    • Does not discover extraneous use cases ("features")
  • Both types of testing are needed
  • White-box testing and black box testing are the extreme ends of a testing continuum.
  • Any choice of test case lies in between and depends on the following:
    • Number of possible logical paths
    • Nature of input data
    • Amount of computation
    • Complexity of algorithms and data structures

Integration Testing

Integration Testing Overview

  • Focus on testing groups of components
  • Two or more components are integrated for testing. When they are tested okay, more components are added for testing
  • Test Strategies:
    • Big Bang Testing
    • Bottom-up Testing
    • Top-down Testing

Integration Test Strategies

  • Big-bang Testing
    • After each component are tested individually, all components are then tested together as a single system
  • Bottom-up Testing
    • Designed for layered system
    • The bottom layer is tested first, and then integrates with components of the next layer up
    • Repeat until all layers are combined and tested
    • Test Drivers are needed to do the testing
      • A routine that calls a subsystem and passes a test case to it
  • Top-down Testing
    • A reversed of Bottom-up Testing
    • The components of top layer is tested first, then integrates with components of the next layer down
    • Repeat until all layers are tested
    • Test stub is needed to do the testing
      • A program or a method that simulates the activity of a missing subsystem by answering to the calling sequence of the calling subsystem and returning back fake data.

Example: Three Layer Call Hierarchy

Big-Bang Approach

Bottom-up Integration

Pros and Cons of bottom up integration testing

  • Bad for functionally decomposed systems:
    • Tests the most important subsystem (UI) last
  • Useful for integrating the following systems
    • Object-oriented systems
    • real-time systems
    • systems with strict performance requirements

Top-down Integration Testing

Pros and Cons of top-down integration testing

  • Test cases can be defined in terms of the functionality of the system (functional requirements)
  • Writing stubs can be difficult: Stubs must allow all possible conditions to be tested.
  • Possibly a very large number of stubs may be required, especially if the lowest level of the system contains many methods.
  • One solution to avoid too many stubs: Modified top-down testing strategy
    • Test each layer of the system decomposition individually before merging the layers
    • Disadvantage of modified top-down testing: Both, stubs and drivers are needed

Sandwich Testing Strategy

  • Combines top-down strategy with bottom-up strategy
  • The system is view as having three layers
    • A target layer in the middle
    • A layer above the target
    • A layer below the target
    • Testing converges at the target layer
  • How do you select the target layer if there are more than 3 layers?
    • Heuristic: Try to minimize the number of stubs and drivers
  • Test in parallel:
    • Middle layer with drivers and stubs
    • Top layer with stubs
    • Bottom layer with drivers
  • Test in parallel:
    • Top layer accessing middle layer (top layer replaces drivers)
    • Bottom accessed by middle layer (bottom layer replaces stubs)

Modified Sandwich Testing Strategy

To be continued on next lecture

  • System Testing
  • Regression Testing
  • Automate Unit Testing
  • Document Your Testing

Verification and Validation

Verification & Validation is the process of checking that a product, service, or system meets specifications and that it fulfils its intended purpose.
Verification is a quality process that is used to evaluate whether or not a product, service, or system complies with a regulation, specification, or conditions imposed at the start of a development phase.
Verification 是驗證,是通過提供客觀證據證明規定的要求是否得到滿足,也就是說,輸入與輸出比較.
Validation 是確認,是在驗證好的基礎上,對預期的使用和應用要求是否得到滿足,也就是說,在確認時,應考慮使用和應用的條件範圍要遠遠大於輸入時確定的範圍.一般是由客戶或代表客戶的人執行.
Validation: Am I building the right product?
Verification: Am I building the product right?

Extra Materials about Software Testing

Application test tools include Source Test Tools, Functional Test Tools, Performance Test Tools, Java Test Tools, Embedded Test Tools, and Database Test Tools.
Opensourcetesting.org aims to boost the profile of open source testing tools within the testing industry, principally by providing users with an easy to use gateway to information on the wide range of open source testing tools available.
35 Performance test tools, including Apache JMeter, benerator, WebLOAD, Grinder, and Siege.
JUnit.org is community site based on the JUnit testing framework. The site is hosted and maintained by Object Mentor, a team of highly experienced software professionals specializing in object-oriented technologies and Agile/XP development methodologies.
Selenium is a test tool for web applications. Selenium tests run directly in a browser, just as real users do. And they run in Internet Explorer, Mozilla and Firefox on Windows, Linux, and Macintosh. No other test tool covers such a wide array of platforms.
The Grinder is a Java load testing framework that makes it easy to run a distributed test using many load injector machines. It is freely available under a BSD-style open-source license.
Apache JMeter is a 100% pure Java desktop application designed to load test functional behavior and measure performance. It was originally designed for testing Web Applications but has since expanded to other test functions.
In the last few years, unit testing has emerged as one of the Good Ideas of our craft. Support for this has grown to as near to unanimous as you could ask for. The last idea that reached this level of consensus was source control in the mid 90s, something that has obviously stuck around. Unit testing very well may be one of the lasting ideas of this decade.

Thanks for Reading

If you would rather like to have this lecture note in printed format, please click the print action link in the top right corner.

If you find any problem in this lecture note, please feel free to tell Steven by steven@findaway.hk

Edit - History - Print - Recent Changes - Search
Page last modified on September 09, 2009, at 11:03 PM