Plugin JUnit. Contents. Mikaël Marche. November 18, 2005



Similar documents
Unit Testing. and. JUnit

IBM Tivoli Workload Scheduler Integration Workbench V8.6.: How to customize your automation environment by creating a custom Job Type plug-in

Capabilities of a Java Test Execution Framework by Erick Griffin

Vim, Emacs, and JUnit Testing. Audience: Students in CS 331 Written by: Kathleen Lockhart, CS Tutor

JobScheduler and Script Languages

Java Interview Questions and Answers

A Practical Guide to Test Case Types in Java

TESTING WITH JUNIT. Lab 3 : Testing

ID TECH UniMag Android SDK User Manual

Unit Testing and JUnit

Approach of Unit testing with the help of JUnit

JUnit - A Whole Lot of Testing Going On

Licensed for viewing only. Printing is prohibited. For hard copies, please purchase from

How To Test A Load Test On A Java Testnet 2.5 (For A Testnet) On A Test Server On A Microsoft Web Server On An Ipad Or Ipad (For An Ipa) On Your Computer Or Ipa

Going Interactive: Combining Ad-Hoc and Regression Testing

Duke University Program Design & Construction Course

Continuous Integration Part 2

Tutorial for Spring DAO with JDBC

Extending XSLT with Java and C#

Author: Sascha Wolski Sebastian Hennebrueder Tutorials for Struts, EJB, xdoclet and eclipse.

Using Extensions or Cordova Plugins in your RhoMobile Application Darryn

Reach 4 million Unity developers

Slides prepared by : Farzana Rahman TESTING WITH JUNIT IN ECLIPSE

DevTest Solutions. Using the SDK. Version 8.0

Announcement. SOFT1902 Software Development Tools. Today s Lecture. Version Control. Multiple iterations. What is Version Control

Developing In Eclipse, with ADT

BPM Scheduling with Job Scheduler

Using JUnit in SAP NetWeaver Developer Studio

Android Application Development: Hands- On. Dr. Jogesh K. Muppala

Testing with Mock Objects

An Overview of Java. overview-1

Crash Course in Java

J a v a Quiz (Unit 3, Test 0 Practice)

Rule based programming with Drools

Unit Testing & JUnit

NeoMAD at a glance for developers

Eclipse Rich Client Platform. Kai Tödter Karsten Becker et al. Organized by:

LAB 1. Familiarization of Rational Rose Environment And UML for small Java Application Development

Braindumps.C questions

Lab Manual: Using Rational Rose

Writing Self-testing Java Classes with SelfTest

How to extend WindowBuilder to support new components. 1. Add component to palette Palette contribution in project

With a single download, the ADT Bundle includes everything you need to begin developing apps:

Testing, Debugging, and Verification

Jemmy tutorial. Introduction to Jemmy testing framework. Pawel Prokop. March 14,

Exception Handling In Web Development DevelopIntelligence LLC

Developing Eclipse Plug-ins* Learning Objectives. Any Eclipse product is composed of plug-ins

CI/CD Cheatsheet. Lars Fabian Tuchel Date: 18.March 2014 DOC:

History OOP languages Year Language 1967 Simula Smalltalk

Effective unit testing with JUnit

Testing the Composability of Plug-and-Play Components

C++ INTERVIEW QUESTIONS

Web development... the server side (of the force)

2. Follow the installation directions and install the server on ccc

Problem 1. CS 61b Summer 2005 Homework #2 Due July 5th at the beginning of class

Test Driven Development

Programming with Android: SDK install and initial setup. Dipartimento di Informatica: Scienza e Ingegneria Università di Bologna

Lab 1A. Create a simple Java application using JBuilder. Part 1: make the simplest Java application Hello World 1. Start Jbuilder. 2.

LAB 3 Part 1 OBJECTS & CLASSES

Classes and Objects in Java Constructors. In creating objects of the type Fraction, we have used statements similar to the following:

Table of Contents. Java CGI HOWTO

Scanner. It takes input and splits it into a sequence of tokens. A token is a group of characters which form some unit.

JUnit Automated Software Testing Framework. Jeff Offutt. SWE 437 George Mason University Thanks in part to Aynur Abdurazik. What is JUnit?

UNIT TESTING. Written by Patrick Kua Oracle Australian Development Centre Oracle Corporation

Creating a Java application using Perfect Developer and the Java Develo...

About the Tutorial. Audience. Prerequisites. Copyright & Disclaimer. AVRO Tutorial

UI Performance Monitoring

Developing Web Views for VMware vcenter Orchestrator

Comparative Analysis of Open Source Automated Software Testing Tools: Selenium, Sikuli and Watir

Introduction to NaviGenie SDK Client API for Android

Generating Automated Test Scripts for AltioLive using QF Test

l What is Android? l Getting Started l The Emulator l Hello World l ADB l Text to Speech l Other APIs (camera, bitmap, etc)

Introduction to Python

Introduction. Why (GIS) Programming? Streamline routine/repetitive procedures Implement new algorithms Customize user applications

Unit-testing with JML

LAB4 Making Classes and Objects

Visual Basic. murach's TRAINING & REFERENCE

Oracle Endeca Information Discovery Integrator

Java CPD (I) Frans Coenen Department of Computer Science

3 Improving the Crab more sophisticated programming

Specialized Programme on Web Application Development using Open Source Tools

The Sun Certified Associate for the Java Platform, Standard Edition, Exam Version 1.0

CS 111 Classes I 1. Software Organization View to this point:

How to utilize Administration and Monitoring Console (AMC) in your TDI solution

LDAPCON Sébastien Bahloul

NetBeans: Universal Tool for Java Development and More. Roman Štrobl Technology Evangelist

How to Program an Android Application to Access and Manage the Wi-Fi Capabilities of a Smartphone

Address Phone & Fax Internet

Frameworks & Android. Programmeertechnieken, Tim Cocx

Tutorial 5: Developing Java applications

TATJA: A Test Automation Tool for Java Applets

Japan Communication India Skill Development Center

Transcription:

Plugin JUnit Mikaël Marche November 18, 2005 JUnit is a Java API enabling to describe unit tests for a Java application. The JUnit plugin inside Salomé-TMF enables one to execute automatically JUnit tests with the TestCase stereotype. Contents 1 Creating a JUnit test suite 2 2 Updating a JUnit test 3 3 Using objects and test parameters 3 4 Example 6 4.1 Creation of the JUnit test suite............................. 6 4.2 Creation of the environment under test......................... 7 4.3 Running the execution.................................. 8 1

1 Creating a JUnit test suite The JUnit plugin enables to create a JUnit test suite by starting from tests declared within an object with the TestCase stereotype. For this, you need a.jar or.zip le containing the compiled code for this object. There exists two modes for creating JUnit test suites. A rst mode is said native, and the other one is linked to the BeanShell plugin. The native mode uses the Java reexion for instantiating the test cases, whereas the BeanShell mode produces BeanShell test scripts which describe the instantiation and the execution of the test class. In the native mode, the.jar or.zip le must countain the test object with the Test- Case stereotype, but also the set of classes necessary for executing the tests. This restriction is caused by the fact that, during the execution of the native mode, there can be no linking to an environment or execution script for loading other classes. For creating a JUnit test suite, after selecting a test suite in the project, choose the menu Tools->Plugin junit, and then the feature Create a JUnit test suite. You should then ll the class creation form as follows: Starting from those informations, the JUnit plugin analyses the selected test class for producing the set of tests contained in this class as automatic test cases inside Salomé (BeanShell or native test cases, depending upon the selected mode). 2

2 Updating a JUnit test Updating a JUnit test will depend upon the selected mode when creating the test suite. In native mode, the creation form enables to update the informations classpath, Tester class, and TestMethod which uniquely identify the test. In BeanShell mode, it is possible to modify the BeanShell script executing the test class (see the documentation for the BeanShell plugin). 3 Using objects and test parameters Whatever the creation mode of a JUnit test case, it is possible to use in the JUnit test class the test parameters linked to one execution and the objects of the Salomé GUI (*=org.objectweb.salome_tmf.data). 3

Name Class Description date Java.lang.Date Execution date time Java.lang.Time Execution time salome_projectname Java.lang.String Name of the current project salome_projectobject *.Project Reference of the project object in Salomé salome_debug boolean False when the script evaluates in the editor salome_execresultobject *.ExecutionResult Reference on the current execution results salome_exectestresultobject *.ExecutionTestResult Reference on the execution result of the current test case salome_campagnename Java.lang.String Name of the current campaign salome_campagneobject *.Campaign Reference of the current campaign salome_environmentname Java.lang.String Name of the current environment salome_environmentobject *.Environment Reference of the current environment salome_execname Java.lang.String Name of the current execution salome_execobject *.Execution Reference on the current execution salome_testname Java.lang.String Name of the current test case salome_testobject *.Test Reference of the current test case salome_suitetestname Java.lang.String Name of the current test suite salome_suitetestobject *.TestList Reference of the current test suite salome_familyname Java.lang.String Name of the current test family salome_familyobject *.Family Reference of the current test family testlog Java.lang.String Test log to add as an attachment at the execution In JUnit native mode, if the test class has got a constructor method which takes as argument a Hashtable, the test class will be instantiated with this constructor method and an Hashtable object which contains all the valued test parameters and the previous objects. import junit.framework.testcase; import org.objectweb.salome_tmf.data.environment; import java.util.hashtable; public class TestParam extends TestCase{ String url_server_env; String Adress_services_schema_Env; String url_server_ds; String Adress_services_schema_DS; public TestParam(String name) { System.out.println("Constructor with String used, arg=" + name); public TestParam(Hashtable params) { System.out.println("Constructor with Hashtable used, arg=" + params); /* sample to salome_tmf object in Java */ Environment env = (Environment)params.get("salome_environmentObject"); /* sample to use environment parameters */ url_server_env = env.getparametervalue("url_server"); Adress_services_schema_Env = env.getparametervalue("adress_services_schema"); /* sample to use dataset parameters */ url_server_ds = (String) params.get("url_server"); Adress_services_schema_DS = (String) params.get("adress_services_schema"); public void testparam() throws Exception { System.out.println("(env) url_server = " + url_server_env); 4

System.out.println("(env) Adress_services_schema = " + Adress_services_schema_Env); System.out.println("(DataSet) url_server = " + url_server_ds); System.out.println("(DataSet) Adress_services_schema = " + Adress_services_schema_DS); In BeanShell mode, the Hashtable assignment is done by calling the method setparam(hashtable) if this method exists in the test class. import junit.framework.testcase; import org.objectweb.salome_tmf.data.environment; import java.util.hashtable; public class TestParam extends TestCase{ String url_server_env; String Adress_services_schema_Env; String url_server_ds; String Adress_services_schema_DS; public void setparam(hashtable params) { /*sample to salome_tmf object in Java Environment env = (Environment)params.get("salome_environmentObject"); /* sample to use environment parameters */ url_server_env = env.getparametervalue("url_server"); Adress_services_schema_Env = env.getparametervalue("adress_services_schema"); /* sample to use dataset parameters */ url_server_ds = (String) params.get("url_server"); Adress_services_schema_DS = (String) params.get("adress_services_schema"); public void testparam() throws Exception { System.out.println("(env) url_server = " + url_server_env); System.out.println("(env) Adress_services_schema = " + Adress_services_schema_Env); System.out.println("(DataSet) url_server = " + url_server_ds); System.out.println("(DataSet) Adress_services_schema = " + Adress_services_schema_DS); 5

4 Example The following example demonstrates how to use the JUnit plugin in native and BeanShell mode, starting from a test class distributed in the release 3.8.1 of JUnit. We suppose that you have compiled two.jar les, one with the compiled code for the class «junit.samples.money.moneytest», and the other one with the compiled code for the class under test called junit.samples.money.money. Nota bene: the example uses the environment scripts for loading the classes of the tested object. It is possible not to use the environment scripts if the.jar le containing the test cases contains also the classes of the tested object. 4.1 Creation of the JUnit test suite Let us call «TestMoney.jar» the le containing the test class junit.samples.money.moneytest. We create a JUnit test suite as follows: The set of tests contained in this class is: 6

4.2 Creation of the environment under test Let us call SUTMoney.jar the le containing the classes required for executing the tests of the class junit.samples.money.moneytest. We will now create an environment whose script will load the classes contained in the le SUTMoney.jar. This operation is required only when the le TestMoney.jar doesn't contain all the classes required for executing the tests. We suppose that we have created an environment JavaMoney, and we will add to this environment a BeanShell script which will load the classes of the le SUTMoney.jar. For lling this task, the following script will make the job: addjar("file:/home/marchemi/pub/junit3.8.1/sutmoney.jar"); The environment script can load several.jar les, and, if needed, can make several BeanShell tasks. Also, it is possible to update the le plugin.xml of the simplejunit directory for loading a set of Java libraries. <?xml version="1.0"?> <!DOCTYPE plugin PUBLIC "-//JPF//Java Plug-in Manifest 0.2" "http://jpf.sourceforge.net/plugin_0_2.dtd"> <plugin id="simplejunit" version="1" class="salometmf_plug.simplejunit.simplejunitplugin"> <requires> <import plugin-id="core"/> </requires> <runtime> <library id="simplejunit" path="simplejunit/simplejunit.jar" type="code"/> <library id="junit" path="simplejunit/libs/httpunits/junit.jar" type="code"/> <library id="httpjunit" path="simplejunit/libs/httpunits/httpunit.jar" type="code"/> <library id="xsdlib" path="simplejunit/libs/libexist/xsdlib.jar" type="code"/> </runtime> 7

<extension plugin-id="core" point-id="testdriver" id="simplejunit.testdriver"> <parameter id="class" value="salometmf_plug.simplejunit.simplejunitplugin"/> <parameter id="name" value="junit"/> <parameter id="description" value="plugin Junit pour la definition de classe de tests"/> <parameter id="extensions" value=".junit"/> </extension> <extension plugin-id="core" point-id="common" id="simplejunit.common"> <parameter id="class" value="salometmf_plug.simplejunit.simplejunitplugin"/> <parameter id="name" value="junittestsuite"/> <parameter id="description" value="creation de suite HTTPJunit TVMoblie"/> </extension> </plugin> 4.3 Running the execution For executing the test suite, it's enough to create a campaign including the JUnit test cases and to associate an execution with the environment JavaMoney. 8