Unit Testing Java using Groovy and Mock Objects Walker Hale Human Genome Sequencing Center Baylor College of Medicine.

Slides:



Advertisements
Similar presentations
Introduction to Eclipse. Start Eclipse Click and then click Eclipse from the menu: Or open a shell and type eclipse after the prompt.
Advertisements

The Point Class public class Point { public double x; public double y; public Point(double x0, double y0) { x = x0; y = y0; } public double distance(Point.
Developing in CAS. Why? As distributed you edit CAS 3 with Eclipse and build with Maven 2 – Best Practice for Release Engineering – Difficult edit-debug.
INHERITANCE BASICS Reusability is achieved by INHERITANCE
METHOD OVERRIDING Sub class can override the methods defined by the super class. Overridden Methods in the sub classes should have same name, same signature.
JAVA BASICS SYNTAX, ERRORS, AND DEBUGGING. OBJECTIVES FOR THIS UNIT Upon completion of this unit, you should be able to: Explain the Java virtual machine.
CHAPTER 1 INTRODUCTION GOALS  To understand the activity of programming  To learn about the architecture of computers  To learn about machine code and.
Aalborg Media Lab 21-Jun-15 Software Design Lecture 1 “ Introduction to Java and OOP”
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,
Begin Java having used Alice Pepper - Some slides from Alice in Action with Java.
Slide 1 of 40. Lecture A The Java Programming Language Invented 1995 by James Gosling at Sun Microsystems. Based on previous languages: C, C++, Objective-C,
Squirrel Programming Language By Nandini Bhatta CS537 Summer 2008.
Tutorial 1 Introduction to Java Programming Bo Chen Department of Computer Science.
CS1020: Intro Workshop. Topics CS1020Intro Workshop Login to UNIX operating system 2. …………………………………… 3. …………………………………… 4. …………………………………… 5. ……………………………………
Writing Methods. Create the method Methods, like functions, do something They contain the code that performs the job Methods have two parts.
Introduction to Java.
Unit 2: Java Introduction to Programming 2.1 Initial Example.
IB Computer Science II Paul Bui
2.2 Information on Program Appearance and Printing.
Groovy WHAT IS IT? HOW DOES IT WORK? IS IT USEFUL?
8 Shell Programming Mauro Jaskelioff. Introduction Environment variables –How to use and assign them –Your PATH variable Introduction to shell programming.
Groovy in 15 minutes… Johannes Carlén Callista Enterprise AB
1 Groovy for Java developers and testers How Java developers and testers could use Groovy to increase their efficiency AUGUST 6, 2015.
Big Java by Cay Horstmann Copyright © 2008 by John Wiley & Sons. All rights reserved. Chapter One: Introduction.
Introduction to Java Thanks to Dan Lunney (SHS). Java Basics File names The “main” method Output to screen Escape Sequence – Special Characters format()
Introduction to Computers and Java Chapter 1.3. A Sip of Java: Outline History of the Java Language Applets A First Java Program Compiling a Java Program.
JAVA (NPRG013) LABS 2012/2013 Jaroslav Keznikl,
CSCE 2013L: Lab 1 Overview  Java Basics The JVM Anatomy of a Java Program  Object-Oriented Programming Overview  Example: Payroll.java JDK Tools and.
OOP (Java): Simple/ OOP (Java) Objectives – –give some simple examples of Java applications and one applet 2. Simple Java Programs Semester.
Java and C# [this is a bonus – it is not a required lesson] ACO101: Introduction to Computer Science.
© 2012 Pearson Education, Inc. All rights reserved. 1-1 Why Java? Needed program portability – Program written in a language that would run on various.
Intro and Review Welcome to Java. Introduction Java application programming Use tools from the JDK to compile and run programs. Videos at
How to Run a Java Program CSE 1310 – Introduction to Computers and Programming Vassilis Athitsos University of Texas at Arlington 1.
Big Java by Cay Horstmann Copyright © 2009 by John Wiley & Sons. All rights reserved. Chapter 1 – Introduction ( ปรับปรุง )
CHAPTER 3 GC Java Fundamentals. 2 BASICS OF JAVA ENVIRONMENT  The environment  The language  Java applications programming Interface API  Various.
Variation Cytoscape 3 app Michael L Heuer dishevelled.org 28 Oct 2013.
C# Versus Java Author: Eaddy, Marc Source: Software Tools for the Professional Programmer. Dr. Dobb's Journal. Feb2001, Vol. 26 Issue 2, p74 Hong Lu CS699A.
CHAPTER 1 INTRODUCTION. CHAPTER GOALS To understand the activity of programming To understand the activity of programming To learn about the architecture.
FIRST JAVA PROGRAM. JAVA PROGRAMS Every program may consist of 1 or more classes. Syntax of a class: Each class can contain 1 or more methods. public.
A First Simple Program /* This is a simple Java program. Call this file "Example.java".*/ class Example { // Your program begins with a call to main().
BUILDING JAVA PROGRAMS CHAPTER 1 ERRORS. 22 OBJECTIVES Recognize different errors that Java uses and how to fix them.
BUILD ON THE POLYGLOT COMPILER FRAMEWORK MIHAL BRUMBULLI 7th Workshop “SEERE” Montenegro-Risan 9-14 September 2007 SimJ Programming Language.
CSci 111 – computer Science I Fall 2014 Cynthia Zickos WRITING A SIMPLE PROGRAM IN JAVA.
Programming Fundamentals 2: Simple/ F II Objectives – –give some simple examples of Java applications and one applet 2. Simple Java.
Introduction to Processing. 2 What is processing? A simple programming environment that was created to make it easier to develop visually oriented applications.
Mixing integer and floating point numbers in an arithmetic operation.
 Instructor: Dr. Jason Nichols –  Office Hours: – 9:30-10:30 M/W/F or by appointment – Business Building.
CS 4244: Internet Programming Network Programming in Java 1.0.
introductory lecture on java programming
CHAPTER 1 INTRODUCTION. CHAPTER GOALS To understand the activity of programming To learn about the architecture of computers To learn about machine code.
Introduction to array: why use arrays ?. Motivational example Problem: Write a program that reads in and stores away 5 double numbers After reading in.
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,
Copyright 2008 by Pearson Education Building Java Programs Chapter 3 Lecture 3-3: Interactive Programs w/ Scanner reading: self-check: #16-19.
Execution ways of program References: www. en.wikipedia.org/wiki/Integrated_development_environment  You can execute or run a simple java program with.
CS 201 Lecture 1 (b) Using an IDE Tarik Booker CS 201: Introduction to Programming California State University, Los Angeles.
21 Oct 2008Presentation to PJUG2 Unit Testing Java Code with Howard Abrams m.
Java Methods and Applications CSIS 3701: Advanced Object Oriented Programming.
CS210 Intermediate Computing with Data Structures (Java)
CompSci 230 Software Construction
Java 24th sep /19/2018 CFILT.
מבוא ל Groovy אליהו חלסצ'י תכנות מתקדם תרגול מספר 12
Writing Methods.
University of Texas Rio Grande Valley Systems Administration CSCI 6175
Tonga Institute of Higher Education
Java Intro.
A Java Application public class Hello { public static void main(String [] args) { System.out.println("Hello, World!"); } } public class.
A Java Application public class Hello { public static void main(String [] args) { System.out.println("Hello, World!"); } } public class.
IB Computer Science II Paul Bui
F II 2. Simple Java Programs Objectives
Objects with ArrayLists as Attributes
Presentation transcript:

Unit Testing Java using Groovy and Mock Objects Walker Hale Human Genome Sequencing Center Baylor College of Medicine

The Plan Groovy makes testing Java better. Motivation Introduce Groovy Apply Groovy to Testing Mock Objects TestNG Grand Demo

The Setting Java shop Subversion — for version control Maven 2 — for most builds Groovy — for various tasks Many apps running against a common database and set of libraries

An Ideal Deliverable in Our Shop Code checked into version control Builds with maven 2 Passes all unit tests $ svn checkout \ $repo/my-project/trunk \ my-project $ cd my-project $ mvn test

The Plot The Motivation –More unit testing! The Insight –Small changes in the difficulty or unpleasantness of a task produce disproportionately large changes in how much that task is performed. Enter Groovy

Groovy in 15 Minutes Almost all Java code is Groovy code –no inner classes – a Groovy adds: –Fun syntactic sugar –Lazy method dispatch –Methods to the standard Java library classes –Closures –Groovy-specific classes Interactive shell

Syntax Sugar // MapSample.java import java.util.*; public class MapSample { public static void main(String[] args) { Map m = new LinkedHashMap (); m.put("red", 1); m.put("blue", 2); System.out.println(m.getClass()); System.out.println(m); } // MapSampleG.groovy def m = [red:1, blue:2] println m.getClass() println m //.toString() for Java-style output

Syntax Sugar $ javac MapSample.java $ java MapSample class java.util.LinkedHashMap {red=1, blue=2} $ groovy MapSampleG.groovy class java.util.LinkedHashMap ["red":1, "blue":2] $ groovyc MapSampleG.groovy $ java -cp `pwd`:$GROOVY_EMBED_JAR MapSampleG class java.util.LinkedHashMap ["red":1, "blue":2]

Lazy Dispatch & Expanding JDK // DispatchSample.groovy def x = "Hello World" def l = ["abc", "def"] println x.split() l.addAll x.split().toList() println l l << "more" << "stuff" println l $ groovy DispatchSample.groovy {"Hello", "World"} ["abc", "def", "Hello", "World"] ["abc", "def", "Hello", "World", "more", "stuff"]

Closures 1 // ClosureSample1.groovy def c = { it + it } println c(2) println c("hello ") def foo(Closure cl) { cl(5, 7) } println foo { x, y -> x + y } println foo { x, y -> x * y } $ groovy ClosureSample1.groovy 4 hello 12 35

Closures 2 // ClosureSample2.groovy [2, 3, 5].each { println it * it } [red:1, blue:2].each { key, value -> println key * value } $ groovy ClosureSample2.groovy red blueblue

Closures 3 // ClosureSample3.groovy def strategies = [ add:{ a,b -> a + b }, mult:{ a,b -> a * b } ] [[1,2], [3,4], [5,6]].each { data -> strategies.each { name, code -> printf "%d %4s %2d\n", data, name, code(data) } $ groovy ClosureSample3.groovy [1, 2] add 3 [1, 2] mult 2 [3, 4] add 7 [3, 4] mult 12 [5, 6] add 11 [5, 6] mult 30

Testing in Groovy Compiled (not limited) with JUnit Adds –GroovyTestCase New assertions, such as shouldFail –GroovyTestSuite Simple command line operation URLs – –

Demo Time!

Resources –Documentation –Differences+from+Java –Testing+Guide