JUnit Eclipse, Java and introduction to Junit. Topics Covered  Using Eclipse IDE  Example Java Programs  Junit Introduction.

Slides:



Advertisements
Similar presentations
JUnit Tutorial Hong Qing Yu Nov JUnit Tutorial The testing problems The framework of JUnit A case study JUnit tool Practices.
Advertisements

Java Testing Tools. junit is a testing harness for unit testing. emma is a code coverage tool. The tools can be used in concert to provide statement and.
1 Unit Testing with JUnit CS 3331 Fall 2009 Kent Beck and Eric Gamma. Test Infected: Programmers Love Writing Tests, Java Report, 3(7):37-50, Available.
J-Unit Framework.
JUnit Automated Software Testing Framework Paul Ammann & Jeff Offutt Thanks in part to Aynur Abdurazik.
Objectives: Test Options JUnit Testing Framework TestRunners Test Cases and Test Suites Test Fixtures JUnit.
JUnit Automated Software Testing Framework Paul Ammann & Jeff Offutt Thanks in part to Aynur Abdurazik.
3. A Testing Framework. © O. Nierstrasz P2 — A Testing Framework 3.2 A Testing Framework Overview  What is a framework?  What is an Annotation?  JUnit.
1 Software Testing and Quality Assurance Lecture 23 – JUnit Tutorial.
Java Intro. A First Java Program //The Hello, World! program in Java public class Hello { public static void main(String[] args) { System.out.println("Hello,
JUnit Introduction and Advanced Features. Topics Covered  Junit Introduction  Fixtures  Test Suites  Currency Example.
01 Introduction1June Introduction CE : Fundamental Programming Techniques.
1 CSC/ECE 517 Fall 2010 Lec. 2 Overview of Eclipse Lectures 1.Overview 2.Installing and Running 3.Building and Running Java Classes 4.Debugging 5.Testing.
Presentation Outline What is JUnit? Why Use JUnit? JUnit Features Design of JUnit Downloading JUnit Writing Tests – TestCase – TestSuite Organizing The.
Unit Testing Discussion C. Unit Test ● public Method is smallest unit of code ● Input/output transformation ● Test if the method does what it claims ●
George Blank University Lecturer. JUnit for Test Driven Development By Vivek Bhagat, George Blank.
CSC3170 Introduction to Database Systems
© Dr. A. Williams, Fall Present Software Quality Assurance – JUnit Lab 1 JUnit A unit test framework for Java –Authors: Erich Gamma, Kent Beck Objective:
Lesson 7 Unit Testing /JUnit/ AUBG ICoSCIS Team Assoc. Prof. Stoyan Bonev March, , 2013 SWU, Blagoevgrad.
Computer Science and Engineering College of Engineering The Ohio State University JUnit The credit for these slides goes to Professor Paul Sivilotti at.
1 v1.6 08/02/2006 Overview of Eclipse Lectures 1.Overview 2.Installing and Running 3.Building and Running Java Classes 4.Refactoring 5.Debugging 6.Testing.
JUnit in Action SECOND EDITION PETAR TAHCHIEV FELIPE LEME VINCENT MASSOL GARY GREGORY ©2011 by Manning Publications Co. All rights reserved. Slides Prepared.
Intro to Java 2 By Geb Thomas Based on the Java TutorialJava Tutorial.
1 Testing With The JUnit Framwork Carl-Fredrik Sørensen, PhD Fellow
Unit testing Unit testing TDD with JUnit. Unit Testing Unit testing with JUnit 2 Testing concepts Unit testing Testing tools JUnit Practical use of tools.
POS 406 Java Technology And Beginning Java Code
Clement Allen, PhD Florida A&M University SUMMER 2006.
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.
Introduction to Eclipse CSC 216 Lecture 3 Ed Gehringer Using (with permission) slides developed by— Dwight Deugo Nesa Matic
ITI 1120 Lab #7. Agenda Topics in this lab: –Methods & Arrays –Library classes –Testing (JUnit) –Strings In this lab, you are going to create your own.
 JAVA Compilation and Interpretation  JAVA Platform Independence  Building First JAVA Program  Escapes Sequences  Display text with printf  Data.
JUnit test and Project 3 simulation. 2 JUnit The testing problems The framework of JUnit A case study Acknowledgement: using some materials from JUNIT.
Introduction to JUnit 3.8 SEG 3203 Winter ‘07 Prepared By Samia Niamatullah.
EIE375 BlueJ: Getting Started Dr Lawrence Cheung.
JUnit Dwight Deugo Nesa Matic
ESO - Garching 23 June – 02 July, 2003 ACS Course JUnit for Java Unit Testing H. Sommer.
Unit Testing with JUnit and Clover Based on material from: Daniel Amyot JUnit Web site.
JUnit Dwight Deugo Nesa Matic
A tool for test-driven development
CS101: Introduction to Computer Science Slides adapted from Sedgewick and Wayne Copyright © Your First Java.
JUnit Don Braffitt Updated: 10-Jun-2011.
JUnit A framework which provides hooks for easy testing of your Java code, as it's built Note: The examples from these slides can be found in ~kschmidt/public_html/CS265/Labs/Java/Junit.
The assignment expressions. The assignment operator in an assignment statement We have seen the assignment statement: Effect: var = expr; Stores the value.
JUnit SWE 619 Summer July 18, 2007 SWE 619 (c) Aynur Abdurazik 2 What is JUnit? Open source Java testing framework used to write and run repeatable.
S Ramakrishnan1 Systems V & V, Quality and Standards Dr Sita Ramakrishnan School CSSE Monash University.
1 Unit Testing with JUnit CS 3331 JUnit website at Kent Beck and Eric Gamma. Test Infected: Programmers Love Writing Tests, Java Report,
1 CSC 216 Lecture 3. 2 Unit Testing  The most basic kind of testing is called unit testing  Why is it called “unit” testing?  When should tests be.
JUnit A Unit Testing Framework for Java. The Objective Introduce JUnit as a tool for Unit Testing Provide information on how to: Install it Build a test.
Test a Little, Code a Little Colin Sharples IBM Global Services New Zealand Colin Sharples IBM Global Services New Zealand.
1 JUnit. 2 Unit Testing with JUnit If code has no automated test case written for it to prove that it works, it must be assumed not to work. An API that.
Computer Science A 1. Course plan Introduction to programming Basic concepts of typical programming languages. Tools: compiler, editor, integrated editor,
Topic: Junit Presenters: Govindaramanujam, Sama & Jansen, Erwin.
COMP Inheritance and Polymorphism Yi Hong June 09, 2015.
Execution ways of program References: www. en.wikipedia.org/wiki/Integrated_development_environment  You can execute or run a simple java program with.
Test automation / JUnit Building automatically repeatable test suites.
SWE 434 SOFTWARE TESTING AND VALIDATION LAB2 – INTRODUCTION TO JUNIT 1 SWE 434 Lab.
Software Construction Lab 10 Unit Testing with JUnit
Unit Testing with JUnit
Chapter No. : 1 Introduction to Java.
Introduction to JUnit CS 4501 / 6501 Software Testing
Software Development Java Classes and Methods
Overview of Eclipse Lectures
JUnit Automated Software Testing Framework
Credit to Eclipse Documentation
Introduction to JUnit CS 4501 / 6501 Software Testing
Java Intro.
Introduction to JUnit IT323 – Software Engineering II
Joel Adams and Jeremy Frens Calvin College
JUnit SWE 619 Spring 2008.
JUnit Dwight Deugo Nesa Matic Portions of the notes for this lecture include excerpts from the Eclipse 3.0 and.
Presentation transcript:

JUnit Eclipse, Java and introduction to Junit

Topics Covered  Using Eclipse IDE  Example Java Programs  Junit Introduction

What is Eclipse? Eclipse is an open source community whose projects are focused on providing an extensible development platform and application frameworks for building software. Download eclipse from Article on using junit with Eclipse

Java Java Tutorials  getStarted/index.html Thinking in Java 3 rd Edition by Bruce Eckel  Or get a printed version

A simple java Program //A Very Simple Example - Hello.java public class Hello { public static void main(String[] args) { System.out.println(“Hello world"); }

Example Compilation #bash# javac Hello.java #bash# java Hello Hello world

Compiling the Eclipse Way Step 1: Create a New Project.  Click on File -> New Project  Select Java Project  Enter the name for the project Step 2: Create a Class File  Click on File -> New Class  Enter the name for the Class (Hello)

Compiling the Eclipse Way (Contd.) Step 3: Copy or create the java program (Hello.java) and Save. Step 4: Run the application  Select Run -> Run and click on Java Application.  Click on the New button and then Click on Run.

Eclipse Output

What is Unit Test?  A definition from IEEE –Testing of individual hardware or software or group of related units  Usually, a unit test is code that tests a "unit": the unit could be a class, a component, a module, a function  Unit Test usually built and run at the development cycle.  Unit test is not functional, application testing  Unit tests are not interactive

We need a framework  A unit testing framework provides  A mechanism to organize and group multiple tests  A simple way to invoke tests  Clear indication of which tests passed/failed  A standard way to write tests and specify expected results.

What is JUnit  JUnit is a Unit Testing Tool for Java  JUnit is a regression testing framework  Programmed by Erich Gamma and Kent Beck  Open Source –Hosted on SourceForge – – –

JUnit’s Features  Assertions for testing expected results  Testing fixtures for sharing common test data  Test suites for easily organizing and running tests  Graphical and textual test runners

JUnit Framework

junit How to Test with JUnit? Student TestCase exercise 1..* TestRunner run 1..* TestStudent test 1 test 2 …

Another Java Example public class Student { private String sname; private String sid; private int score; public Student(String num, String nam, int scr) { sid = num; sname = nam; score = scr; }

Another Example(cont.) public String getNumber() { return sid; } public String getName() { return sname; } public int getScore() { return score; }

Another Example(cont.) public void setNumber(String num) { sid = num; } public void setName(String name) { sname=name; } public void setScore(int scr) { score=scr; } } //End Class Student

Testing the Student Class public class TestStudent { public static void main(String[] args) { Student student=new Student(“043”, “Justin”,100); if (!(student.getName()!=null && student.getName().equals(“Justin”))) System.out.println(“getName method failure”); }

Testing the Junit way import junit.framework.*; public class TestStudent1 { public static void main(String[] args) { Student student = new Student(“043", "Justin", 100); Assert.assertEquals("getName method failure", "Justin", student.getName()); } }

Assert in Junit  Class Assert provide a set of methods  These methods are static  They can throw an object with failure messages. – Messages are only displayed when an assert fails

Junit TestCase public class TestIt extends TestCase { public TestIt (String name) { super (name); } public void testGetMethod() { Student student=new Student(“013", "Justin", 100); assertEquals(“013", student.getNumber()); assertEquals("Justin", student.getName()); assertEquals(100, student.getScore()); }

Junit in Eclipse  Click on File -> New -> Junit Testcase  Give the name for the testcase and create/copy the file in the editor.  Click on Run -> Run. Select Junit Testcase, New and click on Run.

Junit in Eclipse

Assert.assertEquals  assertEquals can be overrided many times for different comparison, such as for String, int  For object comparison, you have to override equals in order to compare fields of two objects

Equals in our example public boolean equals(Object anObject) { if (anObject instanceof Student) { Student aStudent=(Student) anObject; return aStudent.getNumber().equals(getNumber())&& aStudent.getName()==getName()&&aStudent.getS core==getScore(); } return false; }

JUnit Rules and Conventions  Subclass TestCase  Test methods –public void testXXX() [throws …] –Any number of assertions per method