Presentation is loading. Please wait.

Presentation is loading. Please wait.

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.

Similar presentations


Presentation on theme: "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."— Presentation transcript:

1 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 of Science Khon Kaen University

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

3 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.

4 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)); } 1 2 3 4 5 6 7 8 9 10 11 12 4 1 3 5 4 7 6 2 8 9 10 11 12

5 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 { @Test 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)); } @Test 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)); }

6 When junit is executed, the results is shown.

7 Path Testing by EclEmma EclEMMA is an open-source toolkit for measuring and reporting Java code coverage. http://www.eclemma.org/installation.html

8 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?

9 Please you test the program till like this Pass!

10 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

11 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?


Download ppt "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."

Similar presentations


Ads by Google