Docsity

Testing in Software Development: Types and Techniques - Prof. Jeffrey K. Hollingsworth, Study notes of Computer Science

Partial preview of the text

Download Testing in Software Development: Types and Techniques - Prof. Jeffrey K. Hollingsworth and more Study notes Computer Science in PDF only on Docsity!

Announcements

z^

Program #2– Due on Today

z^

Dr. Hollingsworth's Th Office Hour– Will not be held

z^

Reading– Notes (Today)

Testing

z^

Why Test Software– Find bugs in the implementation– Find bugs in the specification

z^

Testing is a major part of Software Development– Around 50% of time in many systems are spent on testing– For life critical software, can be 3-5 times development

z^

Testing Process– Execute a program with the intent of finding an

error

  • Run special code (or inputs) called a test case.– Goal is that each new test should increase likelihood of

finding a yet undiscovered bug.

Tests are an integral part of the software z^ Write Tests as you write software

  • Don’t wait until code is done to write tests– Sometimes write test code

before

software

  • Test each function/method as you write it z^

Tests code can be big– Sample Project:

  • Dyninst 133,000 lines, 16,000 lines of testing code

z^

When the software is “done”, tests continue as part of it– Need to be able to re-test when code changes– Need to validate code on new platforms

  • Sometimes even individual systems

White Box Testing

z^

Examine Statements of a Program– Look for places errors can occur– Writes tests cases designed to have program run all possible

combinations

z^

Try to get maximum

coverage

of a test and test suite

  • Coverage can be expressed in:
    • Lines of a program (statement coverage)• Control points in a program (branch coverage)• Sequences of statements (path coverage)
      • Try to write minimum set of tests to achieve
        • Acceptable coverage level• 100% coverage rarely possible

Black box testing

z^

Test Program based on specifications– Does it perform as expected– Don’t examine how it does the job, just does it do it?

z^

Try to look for:– Incorrect or missing functions– Interface errors– Errors in data structures or external database access

  • After the calls is the file/db correct?
    • Performance errors
      • Timing specs can be a critical as correctness specs
        • Initialization and termination errors
          • Is all allocated memory freed?• Is all memory used initialized?

Notes on Testing

z^

Often Tests may be hybrid of white/black box– Example: Test cases for project #1B

  • Really designed as black box tests for students• After sample solution, initial test cases
    • Look at sample solution for un-tested items– Added additional test cases to increase coverage

z^

Can spend near infinite amounts of effort on testing– Concentrate on tests that demonstrate classes of problems

z^

Approach with the mindset:– What ever can go wrong will go wrong

Using lcov

z^

Statement Coverage tool

z^

Steps:– Compile program with flags -fprofile-arcs -ftest-coverage– Run programs on test cases– lcov -c -d. -o coverage.out– genhtml coverage.out– Creates index.html file in current directory

Demo of lcov viewer

z^

Coverage of Tests on project #1B

z^

Drilling down from summary to individual files

z^

Looking at a given statement– Notice coverage counts for individual statments

Example: Public Test #0 from P

int main(){ int ret;char *ptr;int errorCount=0;assocTable *table;table = createTable(4);if (!table) {printf("ERROR: unable to create a table\n");exit(-1);} ptr = lookupTable(table, "foo") ;if (ptr) { printf("ERROR: found non-existent element foo in table\n");errorCount++;} ret = addTableItem(table, "foo", "bar");if (ret != 0) {printf("ERROR: AddTableItem returned an error\n");errorCount++;} ptr = lookupTable(table, "foo") ;if (!ptr || strcmp(ptr, "bar")) {printf("ERROR: unable to find element bar in table\n");errorCount++;} if (errorCount) {printf("Test simpleOps failed: %d sub-tests failed\n", errorCount);exit(-1);} else {printf("Test simpleOps passed\n");exit(0);} }