Junit in action

  • 3,665 views
Uploaded on

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

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

More in: Technology , Education
  • Full Name Full Name Comment goes here.
    Are you sure you want to
    Your message goes here
    Be the first to comment
No Downloads

Views

Total Views
3,665
On Slideshare
0
From Embeds
0
Number of Embeds
0

Actions

Shares
Downloads
5
Comments
0
Likes
1

Embeds 0

No embeds

Report content

Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
    No notes for slide

Transcript

  • 1. JUNIT IN ACTION Software Engineering (Exercise) Class Valerio Maggio, Ph.D. Candidate valerio.maggio@unina.it Prof.Adriano Peron May, 31st 2013
  • 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. 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. EXERCISE 1 Calculator
  • 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. 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. EXERCISE 1I Stack
  • 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. + 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!