JUNIT IN ACTION
Software Engineering (Exercise) Class
Valerio Maggio, Ph.D. Candidate
valerio.maggio@unina.it
Prof.Adriano...
JUNIT WORDS CLOUD
a.k.a. some random words (almost) related to JUnit
UnitTesting
JavaTesting
Black BoxTesting
Testing fram...
TEST FIXTURES
SetUp testXXX tearDown
fixture: The set of common resources or
data that you need to run one or more
tests.
@...
EXERCISE 1
Calculator
CALCULATOR CLASS
• Requirements:
• Input numbers cannot have
more than 5 digits;
• The calculator can remember
a given (un...
Calculator
+ add (double augend, double addend): double
+ subtract (double minuend, double subtrahend): double
+ multiply ...
EXERCISE 1I
Stack
STACK: LIFO QUEUE
Stack
<<constructor>>
+ Stack(capacity: int)
+ pop(): Process
+ push(Process p): void
Process
+ getName(...
+ enqueue(Process p):void
+ dequeue():Process
<<abstract>>
Queue
*1
_list
Process
FIFOQueue LIFOQueue PriorityQueue
+ addP...
Junit in action
Junit in action
Junit in action
Upcoming SlideShare
Loading in...5
×

Junit in action

4,115

Published on

Junit in Action proposes some example scenarios to apply Unit Testing with the JUnit 4.x Framework

Published in: Technology, Education
0 Comments
1 Like
Statistics
Notes
  • Be the first to comment

No Downloads
Views
Total Views
4,115
On Slideshare
0
From Embeds
0
Number of Embeds
0
Actions
Shares
0
Downloads
9
Comments
0
Likes
1
Embeds 0
No embeds

No notes for slide

Junit in action

  1. 1. JUNIT IN ACTION Software Engineering (Exercise) Class Valerio Maggio, Ph.D. Candidate valerio.maggio@unina.it Prof.Adriano Peron May, 31st 2013
  2. 2. JUNIT WORDS CLOUD a.k.a. some random words (almost) related to JUnit UnitTesting JavaTesting Black BoxTesting Testing framework xUnit Test Suite Test Fixtures Test RunnersSimpleTest Program Testing Automation
  3. 3. TEST FIXTURES SetUp testXXX tearDown fixture: The set of common resources or data that you need to run one or more tests. @Before @After@Test
  4. 4. EXERCISE 1 Calculator
  5. 5. CALCULATOR CLASS • Requirements: • Input numbers cannot have more than 5 digits; • The calculator can remember a given (unique) number; • Only non-negative numbers are allowed. • In case of negative numbers, an exception is thrown! Calculator + add (double augend, double addend): double + subtract (double minuend, double subtrahend): double + multiply (double multiplicand, double multiplier): double + divide (double dividend, double divisor): double + addToMemory(double number): void + recallNumber(): double - memory: double + MAX_DIGITS_LEN: int = 5 <<final>> <<static>>
  6. 6. Calculator + add (double augend, double addend): double + subtract (double minuend, double subtrahend): double + multiply (double multiplicand, double multiplier): double + divide (double dividend, double divisor): double + addToMemory(double number): void + recallNumber(): double + parseExpression(String expression): double - memory: double + MAX_DIGITS_LEN: int = 5 <<final>> <<static>> • Add method parseExpression to the Calculator class and corresponding bunch of tests! • The method takes in input an expression string • (e.g., 1+2-3*4/2) • and returns the correct output result! • (i.e., -3)
  7. 7. EXERCISE 1I Stack
  8. 8. STACK: LIFO QUEUE Stack <<constructor>> + Stack(capacity: int) + pop(): Process + push(Process p): void Process + getName():String + setName(String n): void +getPid(): Integer + setPid(Integer pid): void +getPriority():Integer +setPriority(Integer p): void - name: String - pid: Integer - priority: Integer (default=-1) *1 _list
  9. 9. + enqueue(Process p):void + dequeue():Process <<abstract>> Queue *1 _list Process FIFOQueue LIFOQueue PriorityQueue + addProcess(Process p, Queue q):void + schedule(Queue q):Process Scheduler 1 * _queues Q: How would you test Scheduler? Remember: Unit tests run in isolation!
  1. A particular slide catching your eye?

    Clipping is a handy way to collect important slides you want to go back to later.

×