Unit Testing (Lab 6) Tool Junit on Eclipse SDK By Asst.Prof.Dr. Wararat Songpan(Rungworawut) 322 235 Software Testing Department of Computer Science, Faculty.

Slides:



Advertisements
Similar presentations
AP Computer Science Anthony Keen. Computer 101 What happens when you turn a computer on? –BIOS tries to start a system loader –A system loader tries to.
Advertisements

Chapter 2: Boundary Value Testing : BVT Software Testing
Chapter 6 Path Testing Software Testing
CS110 Programming Language I
J-Unit Framework.
T ESTING WITH J UNIT IN E CLIPSE Farzana Rahman. I NTRODUCTION The class that you will want to test is created first so that Eclipse will be able to find.
Objectives: Test Options JUnit Testing Framework TestRunners Test Cases and Test Suites Test Fixtures JUnit.
Test Driven Development George Mason University. Today’s topics Review of Chapter 1: Testing Go over examples and questions testing in Java with Junit.
CMSC 345, Version 11/07 SD Vick from S. Mitchell Software Testing.
Cell phones off Name signs out – congrats Sean! CSE 116 Introduction to Computer Science for Majors II1.
WISTPC-09 : Session A Tariq M. King PhD Candidate Florida International University Workshop on Integrating Software Testing into Programming.
Introduction to Computer Programming Decisions If/Else Booleans.
22-Jun-15 JUnit. 2 Test suites Obviously you have to test your code to get it working in the first place You can do ad hoc testing (running whatever tests.
24-Jun-15 JUnit. 2 Test suites Obviously you have to test your code to get it working in the first place You can do ad hoc testing (running whatever tests.
24-Jun-15 JUnit. 2 Test suites Obviously you have to test your code to get it working in the first place You can do ad hoc testing (running whatever tests.
TDD Test-Driven Development. JUnit 4.0 To use annotations need to import org.junit.Test To use assertion need to import org.junit.Assert.* No need to.
Unit Testing & Defensive Programming. F-22 Raptor Fighter.
© Dr. A. Williams, Fall Present Software Quality Assurance – JUnit Lab 1 JUnit A unit test framework for Java –Authors: Erich Gamma, Kent Beck Objective:
Concordia University Department of Computer Science and Software Engineering Click to edit Master title style ADVANCED PROGRAMMING PRACTICES Unit Testing.
Lecture 6 Software Testing and jUnit CS140 Dick Steflik.
Principles of Object Oriented Programming Practical session 2 – part A.
JUnit in Action SECOND EDITION PETAR TAHCHIEV FELIPE LEME VINCENT MASSOL GARY GREGORY ©2011 by Manning Publications Co. All rights reserved. Slides Prepared.
Introduction to Testing 1. Testing  testing code is a vital part of the development process  the goal of testing is to find defects in your code  Program.
Intoduction to Unit Testing Using JUnit to structure Unit Testing SE-2030 Dr. Rob Hasker 1 Based on material by Dr. Mark L. Hornick.
CSC 216/001 Lecture 4. Unit Testing  Why is it called “unit” testing?  When should tests be written?  Before the code for a class is written.  After.
Test automation / JUnit Building automatically repeatable test suites.
Refactoring An Automated Tool for the Tiger Language Leslie A Hensley
JUnit Dwight Deugo Nesa Matic
Unit Testing with JUnit and Clover Based on material from: Daniel Amyot JUnit Web site.
JUnit Dwight Deugo Nesa Matic
Simple Java Unit Testing with JUnit 4 and Netbeans 6.1 Kiki Ahmadi JUG-Bonek.
BEGINNING PROGRAMMING.  Literally – giving instructions to a computer so that it does what you want  Practically – using a programming language (such.
Java Basics Hussein Suleman March 2007 UCT Department of Computer Science Computer Science 1015F.
By Rick Mercer with help from Kent Beck and Scott Ambler Java Review via Test Driven Development (TDD)
JUnit Eclipse, Java and introduction to Junit. Topics Covered  Using Eclipse IDE  Example Java Programs  Junit Introduction.
1 Unit Testing with JUnit CS 3331 JUnit website at Kent Beck and Eric Gamma. Test Infected: Programmers Love Writing Tests, Java Report,
JUnit in Action SECOND EDITION PETAR TAHCHIEV FELIPE LEME VINCENT MASSOL GARY GREGORY ©2011 by Manning Publications Co. All rights reserved.
2-1 By Rick Mercer with help from Kent Beck and Scott Ambler Java Review via Test Driven Development.
Unit, Regression, and Behavioral Testing Based On: Unit Testing with JUnit and CUnit by Beth Kirby Dec 13, 2002 Jules.
CS-2852 Data Structures LECTURE 7B Andrew J. Wozniewicz Image copyright © 2010 andyjphoto.com.
Justin Bare and Deric Pang with material from Erin Peach, Nick Carney, Vinod Rathnam, Alex Mariakakis, Krysta Yousoufian, Mike Ernst, Kellen Donohue Section.
Computer Science A 1. Course plan Introduction to programming Basic concepts of typical programming languages. Tools: compiler, editor, integrated editor,
Software Design– Unit Testing SIMPLE PRIMER ON Junit Junit is a free simple library that is added to Eclipse to all automated unit tests. The first step,
Computer Science I Lab 1 ISMAIL ABUMUHFOUZ | CS 180.
Test automation / JUnit Building automatically repeatable test suites.
Testing and Debugging UCT Department of Computer Science Computer Science 1015F Hussein Suleman March 2009.
SWE 434 SOFTWARE TESTING AND VALIDATION LAB2 – INTRODUCTION TO JUNIT 1 SWE 434 Lab.
CompSci 280 S Introduction to Software Development
Unit Testing.
Software Construction Lab 10 Unit Testing with JUnit
Unit Testing with JUnit
Testing Tutorial 7.
Dept of Computer Science University of Maryland College Park
Chapter 2 Elementary Programming
Introduction to JUnit CS 4501 / 6501 Software Testing
Chapter 5 Retrospective on Functional Testing Software Testing
Computer Science 209 Testing With JUnit.
Software Engineering 1, CS 355 Unit Testing with JUnit
Getting Started ARCS Lab..
Test-first development
Writing Methods.
How to Run a Java Program
Ruby Testing 2, 11/9/2004.
Credit to Eclipse Documentation
Introduction to JUnit CS 4501 / 6501 Software Testing
Introduction to JUnit IT323 – Software Engineering II
JUnit Reading: various web pages
UNIT TESTING TOOLS Workshop on Integrating Software
Junit Tests.
Principles of Object Oriented Programming
Presentation transcript:

Unit Testing (Lab 6) Tool Junit on Eclipse SDK By Asst.Prof.Dr. Wararat Songpan(Rungworawut) Software Testing Department of Computer Science, Faculty of Science Khon Kaen University

Junit is a tool for unit testing in Java Language by Erich Gamma and Kent Beck open source framework

Benefit of Junit It is a framework that help to test source code more effectiveness. ◦ Automated Testing ◦ No impact with internal program. ◦ Find defects by source code viewing.

Example Grade program Assume that we test the program Grade.java public class Grade { public static char getLetterGrade(int mark) { if (mark >= 75) { return 'A'; } else if (mark >= 60) { return 'B'; } else if (mark > 50) { return 'C'; } else if (mark >= 30) { return 'D'; } else { return 'F'; } public static void main(String[] args) { // TODO Auto-generated method stub System.out.print(getLetterGrade(70)); }

Create Test cases by Junit Test file is created by Junit and set the name is GradeUnitTest.java import static org.junit.Assert.*; import org.junit.Test; public class GradeUnitTest public void testTypical() { // test a typical value in partitions EC assertEquals('A', Grade.getLetterGrade(95)); assertEquals('B', Grade.getLetterGrade(72)); assertEquals('C', Grade.getLetterGrade(55)); assertEquals('C', Grade.getLetterGrade(30)); assertEquals('F', Grade.getLetterGrade(20)); public void testEC() { // test the boundaries of the partitions EC assertEquals('A', Grade.getLetterGrade(100)); assertEquals('A', Grade.getLetterGrade(75)); assertEquals('B', Grade.getLetterGrade(74)); assertEquals('B', Grade.getLetterGrade(60)); assertEquals('C', Grade.getLetterGrade(59)); assertEquals('C', Grade.getLetterGrade(50)); assertEquals('D', Grade.getLetterGrade(49)); assertEquals('D', Grade.getLetterGrade(30)); assertEquals('F', Grade.getLetterGrade(29)); assertEquals('F', Grade.getLetterGrade(0)); }

When junit is executed, the results is shown.

Path Testing by EclEmma EclEMMA is an open-source toolkit for measuring and reporting Java code coverage.

The Question 1: Why is the program shown Defects on the screen in part of Junit running? Please fix it!! The Question II: Note your EclEmma running, How many percentages of your unit testing before and after fixed the program?

Please you test the program till like this Pass!

Other method in Junit test Assert Method is method in Junit that checks test cases will be alert when do not meet with excected results Assert MethodExpected Results assertTrue()When we expect the result is true assertFalse()When we expect the result false assertNull()When we expect the result null assertNotNull()When we expect the result not null **assertEquals()When we expect the result is equals assertSame()When we expect the result the same object assertNotSame()When we expect the result not the same object Fail()When we expect the result is always fails

Lab6 Create Project as Calculate in sheets Chapter 6 (page 41) and create Junit test follows as table in page 45 to coverage all path as possible. How many percentages of your Junit code to test Calculate program using EclEmma?