Download Writing a Check unit test

Survey
yes no Was this document useful for you?
   Thank you for your participation!

* Your assessment is very important for improving the workof artificial intelligence, which forms the content of this project

Document related concepts
no text concepts found
Transcript
Introduction to
Software Testing
(Paul deGrandis)
[Reading assignment: Chapter 15, pp. 231-252
and notes by Paul deGrandis]
Overview
•
•
Terms and Definitions
Tool Overview
•
•
•
•
•
•
Static Checkers
Unit Testing
Coverage and Profiling
Memory Analysis
Bug Reporting and Tracking
Continuous Integration
NOTE
• All the material and examples from
•
here on are generated using a single
makefile.
Log into tux, then:
wget http://www.pauldee.org/vandvmakefile
mv vandvmakefile Makefile
• Export your classpath:
• To make and download all tools and
export CLASSPATH=`pwd`/junit/junit-4.4.jar:`pwd`/emma/emma.jar:.
examples:
make
Tool Overview
• Verification
•
•
•
Static Checking
Unit Tests for code correctness
Memory and performance specifications
•
Unit Tests for behavior and requirements
• Validation
Static Checkers
• Does not execute the code
• Finds suspicious code or
•
security vulnerabilities
Tools
Cyclone - a safe C
• C - SPLINT,
•
GNU Compiler Collection
GCC Warnings
Java - FindBugs, PMD
FindBugs - Find Bugs in Java
Static Checkers - C
Screenshots
Static Checkers - C
Demo
• Installation of SPLINT
• Compiling using GCC Warning
• Running Splint
Static Checkers - C
Demo
• Installation of SPLINT
•
•
•
Download
wget http://www.splint.org/downloads/splint-3.1.2.src.tgz
Untar
tar -xzvf splint-3.1.2.src.tgz
Make (during make, splint checks itself)
cd splint-3.1.2/
./configure
make
Static Checkers - C
Demo
• Compiling using GCC Warnings
•
see the screenshot three slides back
Static Checkers - C
Demo
• Running SPLINT
•
•
Simple and Basic
splint -preproc +weak +show-summary +stats ../src/*.c
Dependable Software
splint -preproc +checks +show-summary +stats ../src/*.c
Static Checkers - Java
Screenshots
Static Checkers - Java
Demo
• Installation of FindBugs
• Running FindBugs
Static Checkers - Java
Demo
• Installation of FindBugs
•
•
Download
wget http://prdownloads.sourceforge.net/findbugs/findbugs-1.2.1.tar.gz
Untar
tar -xvzf findbugs-1.2.1.tar.gz
cd findbugs-1.2.1
Static Checkers - Java
Demo
• Running FindBugs
•
Run It
./findbugs
Unit Tests
• Validate a unit of code; smallest testable
part
• Executes the code in a sandboxed
environment
• Testing mostly for functional requirements
• can also test some non-functional requirements
• Many approaches and schools of thought
•
History Based, Risk Based, Data Path, DOE
Unit Tests Frameworks-C
Screenshots
Check Unit Test Framework
http://check.sourceforge.net
Unit Tests FrameworksC
Demo
http://check.sourceforge.net/doc/check.html/index.html
• Installation of Check
• Writing a Check unit test
• Compiling your test(s)
• Running your test(s)
Unit Tests FrameworksC
Demo
• Installation of Check
•
•
•
Download
wget http://downloads.sourceforge.net/check/check-0.9.5.tar.gz
Untar
tar -xvzf check-0.9.5.tar.gz
Make (notice the GCC warnings passed)
cd check-0.9.5
./configure
make
Unit Tests FrameworksC
Demo
• Writing a Check unit test
•
•
•
•
Write your test fixtures
Write your test(s)
Write your test suite
Write your main method (execute your
suite)
Unit Tests FrameworksC
Demo
• Writing a Check unit test
•
Write your test fixtures
Unit Tests FrameworksC
Demo
• Writing a Check unit test
•
Write your test(s)
Unit Tests FrameworksC
Demo
• Writing a Check unit test
•
Write your test suite
Unit Tests FrameworksC
Demo
• Writing a Check unit test
•
Write your main method (execute your
suite)
Unit Tests FrameworksC
Demo
• Compiling your test(s)
•
See README in check/checkexample/square
Unit Tests FrameworksC
Demo
• Running your test(s)
•
See README in check/checkexample/square
Unit Tests Frameworks-Java
Screenshots
Unit Tests FrameworksJava
Demo
http://junit.sourceforge.net/ (look at the cookbook)
• Installation of Junit
• Writing a Junit unit test
• Compiling your test(s)
•
• Running your test(s)
Just use javac
•
just use java
Unit Tests FrameworksJava
Demo
• Installation of Junit
•
•
Download
wget http://downloads.sourceforge.net/junit/junit-4.4.jar
Add the jar to your classpath
export CLASSPATH=$CLASSPATH:`pwd`/junit-4.4.jar:.
Unit Tests FrameworksJava
Demo
•Writing a Junit unit test
•Write your test fixtures
•Write your test(s)
•Write your test suite
•Write your main method (execute your suite)
Unit Tests FrameworksJava
Demo
• Writing a Junit unit test
•
Write your test fixtures
Unit Tests FrameworksJava
Demo
• Writing a Junit unit test
•
Write your test(s)
Unit Tests FrameworksJava
Demo
• Writing a Junit unit test
•
Write your test suite(s)
Unit Tests FrameworksJava
Demo
• Writing a Junit unit test
•
Write your main method
Code Coverage
• Degree to how much code was tested
(E.g., How confident are we in our tests and code)
• Criteria:
•
•
•
Statement - Has each line been executed
Condition - Every evaluation (if/else, try/catch, switch, loop)
Path - Every route of code
Code Coverage - C
Screenshots
GCC - GCOV
Code Coverage - C
Demo
See the Screenshot one slide back
Code Coverage - Java
Screenshots
EMMA
http://emma.sourceforge.net/intro.html
Code Coverage - Java
•
Demo
Installation of Emma
Download
•
•
•
•
wget http://downloads.sourceforge.net/emma/emma-2.0.5312-lib.zip
Unzip
unzip emma-2.0.5312-lib.zip
Instrument Your Code
java -cp emma.jar:./sample:../junit/junit-4.4.jar emma instr -outdir
./sampleout -cp ./sample/ SimpleTest
Run Your Code and Generate a report
java SimpleTest
java -cp emma.jar emma report -r html -in
sampleout/coverage.em,sampleout/coverage.ec
Memory Analysis
• Sandboxes an application in a VM
• Uses:
•
•
•
Memory Leak - allocate memory, but don’t free
Buffer Overflow - access memory outside of a fixed buffer
Profiling - performance analysis
Memory Analysis - C
Screenshots
Valgrind
Memory Analysis - C
Demo
• Installation of Valgrind
•
•
•
Download
wget http://downloads.sourceforge.net/check/check-0.9.5.tar.gz
Untar
tar -xvjf valgrind-3.2.3.tar.bz2
Make (notice the GCC warnings passed)
cd valgrind-3.2.3
./configure
make
Memory Analysis - C
Demo
• Running of Valgrind
•
•
•
Compile with debugging enabled
gcc -g myprog.c
Run Valgrind
valgrind --leak-check=yes myprog arg1 arg2
Full tutorial and infoformation
http://valgrind.org/docs/manual/quick-start.html#quick-start.intro
Memory Analysis - Java
Screenshots
JConsole
Issue and Bug Tracking
• Organizes and tracks issues,
•
•
enhancements, features, and bugs in
a software system
Usually contains a database backend
and a web frontend
Generate report of project and team
metrics and productivity
Issue and Bug Tracking
• Trac (
• Roundup (
• Tracker (
)
http://trac.edgewall.org/
http://roundup.sourceforge.net/)
http://tracker.rubyforge.org/)
Continuous Integration
• Committing changes early and often
• Building and testing at least nightly
• If code breaks, revert
• Integration issues discovered early as
developers work with the latest code
You now know …
•
•
•
•
•
… static checkers
… unit testing tools
… coverage and profiling tools
… memory analysis tools
… Bug reporting and tracking tools
Related documents