Introduction to the Semantic Web

Download Report

Transcript Introduction to the Semantic Web

Unit and Functional Testing
in Android
Presenter: Mihai Fonoage
Class: Android Mobile Component
Development
Date: April 6, 2010
Outline
•
•
•
•
•
Introduction
Unit Testing: JUnit Framework
Java Application Example: Calculator
Functional Testing
Android Application Example: Calculator
2
Introduction
• Two flavors of testing described:
– Unit Testing
• Test if your code runs correctly
– Functional Testing
• Testing done on a component of your system to
make sure it complies with the functional
requirements
• Unit tests tell a developer that the code
is doing things right; functional tests tell a
developer that the code is doing the right
things
3
Outline
•
•
•
•
•
Introduction
Unit Testing: JUnit Framework
Java Application Example: Calculator
Functional Testing
Android Application Example: Calculator
4
Unit Testing: JUnit Framework
• Unit Testing:
– Unit = smallest testable part of an application
(i.e. a function/method)
– Goal: isolate each part of your application and
make sure that it works correctly
– Written from a developer’s perspective
– Before writing tests, the developer needs to
understand the specification and
requirements of the feature to be tested
• Accomplished through use cases and user stories
5
Unit Testing: JUnit Framework (2)
• Flow
Create/Modify
your
Java class
Create your
JUnit tests
Compile and
Execute your
tests
Collect test
results
Yes
Failure?
No
6
Unit Testing: JUnit Framework (3)
• JUnit: an open source framework for
writing and running tests
Unit Test = test of a single isolated component
in a repeatable way
• JUnit Features:
– Assertions for testing expected results
– Test fixtures for sharing common test data
– Test runners for running tests
• Current version 4.x
– Takes advantage of Java 5 Annotations
7
Unit Testing: JUnit Framework (4)
• How does it work?
– Assert statements
• Assert something is true: assertTrue(expected,
actual), assertTrue(boolean condition)
• Assert something is false: assertFalse(boolean
condition)
• Assert equality: assertEquals(expected, actual)
– When an assert fails, your test failed for that
particular case, hence your code needs to be
fixed.
8
Unit Testing: JUnit Framework (4)
• JUnit Annotations:
– @Test
• Mark your test cases with @Test annotation
– @Before and @After
• Used for “setup” and “tearDown” methods
• They run before and after every test case
• Write your initialization code and cleanup code there
– @BeforeClass and @AfterClass
• Used for class wide “setup” and “tearDown” methods
• They run one time, before and after the all test cases.
– @Ignore
• Used for test cases you want to ignore
– On methods that are not fully implemented yet (are not ready to
be ran)
9
Unit Testing: JUnit Framework (4)
– Exception Handling
• Use the “expected” parameter with @Test
annotation for test cases that expect exceptions
– @Test(expected = ArithmeticException.class
)
10
Outline
•
•
•
•
•
Introduction
Unit Testing: JUnit Framework
Java Application Example: Calculator
Functional Testing
Android Application Example: Calculator
11
Outline
•
•
•
•
•
Introduction
Unit Testing: JUnit Framework
Java Application Example: Calculator
Functional Testing
Android Application Example: Calculator
12
Functional Testing
• Functional tests are written from a user's
perspective
– These tests confirm that the system does
what users are expecting it to do
• Focus on system behavior that users are
interested in
– The tester interacts with the system to
determine if it behaves correctly
• Not the desired path to take
13
Outline
•
•
•
•
•
Introduction
Unit Testing: JUnit Framework
Java Application Example: Calculator
Functional Testing
Android Application Example: Calculator
14