Junit in action
Upcoming SlideShare
Loading in...5
×
 

Junit in action

on

  • 3,721 views

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

Statistics

Views

Total Views
3,721
Views on SlideShare
3,721
Embed Views
0

Actions

Likes
1
Downloads
4
Comments
0

0 Embeds 0

No embeds

Accessibility

Categories

Upload Details

Uploaded via as Adobe PDF

Usage Rights

CC Attribution-ShareAlike LicenseCC Attribution-ShareAlike License

Report content

Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
  • Full Name Full Name Comment goes here.
    Are you sure you want to
    Your message goes here
    Processing…
Post Comment
Edit your comment

Junit in action Junit in action Presentation Transcript

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