JUnit Adam Heath. What is JUnit?  JUnit is a unit testing framework for the Java programming language  It allows developers to swiftly and easily test.

Slides:



Advertisements
Similar presentations
Computer Science 209 Testing With JUnit. Why Test? I don ’ t have time, I ’ ve got a deadline to meet The more pressure I feel, the fewer tests I will.
Advertisements

J-Unit Framework.
MAHDI OMAR JUNIT TUTORIAL. CONTENTS Installation of Junit Eclipse support for Junit Using Junit exercise JUnit options Questions Links and Literature.
Objectives: Test Options JUnit Testing Framework TestRunners Test Cases and Test Suites Test Fixtures JUnit.
1-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.
Approach of Unit testing with the help of JUnit Satish Mishra
Well-behaved objects 4.0 Testing. 2 Objects First with Java - A Practical Introduction using BlueJ, © David J. Barnes, Michael Kölling Main concepts to.
Introduction to Eclipse, Unit Testing and JUnit David Rabinowitz.
1 Software Testing and Quality Assurance Lecture 23 – JUnit Tutorial.
JUnit, Revisited 17-Apr-17.
21-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.
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.
JUnit. Why is testing good? Due to psychological factors, programmers are bad testers. A computer can test much faster than a human Philosophy: “If it.
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.
26-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.
Testowanie kodu Bartosz Baliś, Na podstawie prezentacji Satisha Mishra Iana Sommerville Erica Braude.
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.
15-Jul-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 (testing whatever occurs.
Automated Testing Nathan Weiss April 23, Overview History of Testing Advantages to Automated Testing Types of Automated Testing Automated Testing.
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.
Introduction to Unit Testing Jun-Ru Chang 2012/05/03.
Principles of Object Oriented Programming Practical session 2 – part A.
Testing in Extreme Programming
Test Automation For Web-Based Applications Portnov Computer School Presenter: Ellie Skobel.
Sadegh Aliakbary Sharif University of Technology Spring 2012.
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.
GIT and JUnit Dr. Andrew Wallace PhD BEng(hons) EurIng
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.
CSC 395 – Software Engineering Lecture 10: Execution-based Testing –or– We can make it better than it was. Better...faster...agiler.
Well-behaved objects Main concepts to be covered Testing Debugging Test automation Writing for maintainability Objects First with Java - A Practical.
Advanced Programming in Java
Introduction to JUnit 3.8 SEG 3203 Winter ‘07 Prepared By Samia Niamatullah.
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
A tool for test-driven development
Simple Java Unit Testing with JUnit 4 and Netbeans 6.1 Kiki Ahmadi JUG-Bonek.
By Rick Mercer with help from Kent Beck and Scott Ambler Java Review via Test Driven Development (TDD)
Sadegh Aliakbary Sharif University of Technology Spring 2011.
EMBEDDED REAL-TIME, INC. December 8, 2015 Java Unit Mark Mosher Rochester Java Users Group.
JUnit Don Braffitt Updated: 10-Jun-2011.
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.
2-1 By Rick Mercer with help from Kent Beck and Scott Ambler Java Review via Test Driven Development.
CS-2852 Data Structures LECTURE 7B Andrew J. Wozniewicz Image copyright © 2010 andyjphoto.com.
Well-behaved objects Main concepts to be covered Testing Debugging Test automation Writing for maintainability Objects First with Java - A Practical.
Unit Testing in Eclipse Presented by David Eisler 08/09/2014.
Test automation / JUnit Building automatically repeatable test suites.
Software Engineering Lecture 11 Software Testing Presenter: Josef Hallberg 1.
Well-behaved objects Main concepts to be covered Testing Debugging Test automation Writing for maintainability © 2017 Pearson Education, Inc. Hoboken,
Unit Testing.
Unit Testing with JUnit
Computer Science 209 Testing With JUnit.
Software Engineering 1, CS 355 Unit Testing with JUnit
JUnit 28-Nov-18.
JUnit 28-Nov-18.
JUnit 7-Dec-18.
JUnit 11-Jan-19.
Testing 24-Feb-19.
CS 240 – Advanced Programming Concepts
JUnit 18-Apr-19.
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.
JUnit 31-May-19.
Principles of Object Oriented Programming
Presentation transcript:

JUnit Adam Heath

What is JUnit?  JUnit is a unit testing framework for the Java programming language  It allows developers to swiftly and easily test parts of Java applications  It is part of the xUnit family of tools first designed by Kent Beck for the Smalltalk programming language

Unit Testing  Used for “Bottom Up” testing  Test “units” of code  Class → Test Class  Orderless  Tests written early  Can be automated  Ran often

JUnit Assertions  All asserts have an optional first argument 'message' which would be output on failure assertArrayEquals(x, y) assertEquals(x, y) assertFalse(boolean) assertTrue(boolean) fail() assertNull(object) assertNotNull(object) assertSame(object) assertNotSame(object) assertThat(x, Matcher)

JUnit Testing public class Maths { private int[] arr; private int count, total; // constructor, initiate to zero public Maths(); //Divide two numbers public static double divide(int a, int b); //Add integers to sum public void addtosum(int a); //Get the average public double average(); //Get the array storing our integers public int[] getArr(); }//end class Maths

JUnit Testing import org.junit.* ; public class MathsTest public void test_divide() { assertEquals(Maths.divide(4,2), 2.0) ; assertEquals(Maths.divide(2,4), 0.5) ; public void test_divideZero() { Maths.divide(4,0); public void test_addtosum() { Maths m = new Maths(); m.addtosum(4); int[] expected = { 4 }; assertArrayEquals(expected, m.getArr()) m = null; }

JUnit public void test_addtosumMore() { Maths m = new Maths(); m.addtosum(9878); m.addtosum(0); int[] expected = { 9878, 0 }; assertArrayEquals(expected, m.getArr()) m = null; public void test_average() { Maths m = new Maths(); m.addtosum(5); m.addtosum(8); m.addtosum(23); m.addtosum(1); assertEquals(m.average(), 9.25) ; m = null; } }//class

JUnit public void beginMaths() { Maths m = new Maths(); public void endMaths() { m = null; } Fixtures allow us to define methods to be run before and after every test in that class We can also annotations

JUnit public void beginMaths() { Maths m = new Maths(); public void endMaths() { m = null; public void test_addtosum() { m.addtosum(4); int[] expected = { 4 }; assertArrayEquals(expected, m.getArr()) } This test would run: beginMaths() test_addtosum() endMaths()

Running JUnit  Junit should be added to Java CLASSPATH  Text interface java org.junit.runner.JUnitCore MathsTest  GUIs are available  Integrated into IDE

Advantages  Fast  Early discovery of errors  Bug fixing  Regression testing  Time saved in testing  Can help with design  Can help to document the system

Disadvantages  Developer overhead  Does not deal with Integration or Customer testing  Tests must be kept up to date  Must be ran often

Questions?