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



Similar documents
Hypercosm. Studio.

Editing Files on Remote File Systems

Introduction to Mac OS X

Introduction to Microsoft Access 2003

Before you can use the Duke Ambient environment to start working on your projects or

Employee Appointment Books. User s Manual

Word 2007: Basics Learning Guide

Computer Basics: Tackling the mouse, keyboard, and using Windows

Unix Tools. Overview. Editors. Editors nedit vi Browsers/HTML Editors Mail Tools Utilities xv xman ftp

Command Line - Part 1

Computer Programming In QBasic

Ohio University Computer Services Center August, 2002 Crystal Reports Introduction Quick Reference Guide

Intellect Platform - The Workflow Engine Basic HelpDesk Troubleticket System - A102

Microsoft Excel 2010 Linking Worksheets and Workbooks

Office of History. Using Code ZH Document Management System

VIP Quick Reference Card

Adobe Dreamweaver - Basic Web Page Tutorial

TABLE: The 2420 Telephone Components

Excel Templates. & Quote/Invoice Maker for ACT! Another efficient and affordable ACT! Add-On by V

Book Builder Training Materials Using Book Builder September 2014

AppShore Premium Edition Campaigns How to Guide. Release 2.1

Introduction to MS WINDOWS XP

FOR PREPARING THE CALL REPORT EXCEL DATA FILE AND ELECTRONIC SUBMISSION OF THE CRS AND E-DATA

TM Online Storage: StorageSync

WA2099 Introduction to Java using RAD 8.0 EVALUATION ONLY. Student Labs. Web Age Solutions Inc.

Introduction To Microsoft Office PowerPoint Bob Booth July 2008 AP-PPT5

Tips and Tricks SAGE ACCPAC INTELLIGENCE

Introduction to Computers

TESTING WITH JUNIT. Lab 3 : Testing

Jump-Start Tutorial For ProcessModel

#65 4GHGTGPEG")WKFG #FXCPEGF"6GTOKPCN"5QHVYCTG 8GTUKQP"502 HQT"%QPVTQNNGT/#% Catalog # Rev.02

Lab 2: MS ACCESS Tables

Lotus Notes Client Version 8.5 Reference Guide

SPSS: Getting Started. For Windows


3 IDE (Integrated Development Environment)

Virtual Communities Operations Manual

Using SQL Server Management Studio

Appendix K Introduction to Microsoft Visual C++ 6.0

Hands-On Lab. Web Development in Visual Studio Lab version: Last updated: 12/10/2010. Page 1

Windows PowerShell Essentials

Microsoft Word 2010 Tutorial

Getting Started with KompoZer

Microsoft Access 2010 handout

Week 2 Practical Objects and Turtles

NJCU WEBSITE TRAINING MANUAL

The first program: Little Crab

Advanced Presentation Features and Animation

Appointment Scheduler

Mouse and Keyboard Skills

Programming with the Dev C++ IDE

Outlook Tips & Tricks. Training For Current & New Employees

Introduction to Eclipse

2 The first program: Little Crab

IBM Operational Decision Manager Version 8 Release 5. Getting Started with Business Rules

MICROSOFT OUTLOOK 2010 WORK WITH CONTACTS

Appendix M: Introduction to Microsoft Visual C Express Edition

Hermes.Net IVR Designer Page 2 36

Metatrader 4 Tutorial

Introduction to Microsoft Access XP

NASA Workflow Tool. User Guide. September 29, 2010

Microsoft Access 2010 Part 1: Introduction to Access

CGS 1550 File Transfer Project Revised 3/10/2005

University of Toronto

How to setup a Printer to Print from Solaris to MegaRIP and BlackMagic

RX-6 Six In - One Out All in One Receive Antenna Switch Local and Remote Control System RX6ACI User Manual Version 2.1

Tutorial: Creating a form that s the results to you.

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

Summary. Load and Open GaussView to start example

How to Configure Windows 8.1 to run ereports on IE11

VI(Visual) Editor Reference manual

Search and Replace in SAS Data Sets thru GUI

MICROSOFT ACCESS 2003 TUTORIAL

Outlook Web App McKinney ISD 5/27/2011

SmartBar for MS CRM 2013

For Introduction to Java Programming, 5E By Y. Daniel Liang

Enhanced Formatting and Document Management. Word Unit 3 Module 3. Diocese of St. Petersburg Office of Training Training@dosp.

MICROSOFT WORD TUTORIAL

Appendix A How to create a data-sharing lab

Business Objects. Report Writing - CMS Net and CCS Claims

Web Ambassador Training on the CMS

Mentor Tools tutorial Bold Browser Design Manager Design Architect Library Components Quicksim Creating and Compiling the VHDL Model.

Introduction to Word 2007

FastTrack Schedule 10. Tutorials Manual. Copyright 2010, AEC Software, Inc. All rights reserved.

How to Excel with CUFS Part 2 Excel 2010

Analyzing PDFs with Citavi 5

OPERATION MANUAL. MV-410RGB Layout Editor. Version 2.1- higher

CS 106 Introduction to Computer Science I

Getting Started with Command Prompts

Dalhousie University CSCI 2132 Software Development Winter 2015 Lab 7, March 11

A Short Introduction to Writing Java Code. Zoltán Majó

SpaceClaim Introduction Training Session. A SpaceClaim Support Document

A QUICK OVERVIEW OF THE OMNeT++ IDE

OWNERS MANUAL. Status Monitor. for Windows 95, 98, ME, NT 4, 2000 & XP. SIGNALCRAFTERS TECH, INC.

Visual Studio 2008 Express Editions

Smart Web. User Guide. Amcom Software, Inc.

Hands-on Exercise 1: VBA Coding Basics

How To Use Databook On A Microsoft Powerbook (Robert Birt) On A Pc Or Macbook 2 (For Macbook)

Hands-On: Introduction to Object-Oriented Programming in LabVIEW

Transcription:

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

Overview Vim and Emacs are the two code editors available within the Dijkstra environment. While both perform essentially the same function, each has it own characteristics, advantages, and disadvantages. JUnit tests allow you to test how your code runs under various situations. Using JUnit is required for CS 331.

Vim Standing for vi improved (vi is a text editor for Unix systems), Vim was released in 1991 Vim is a free and open source software Vim is entirely a text editor, it has no graphics whatsoever. Graphic versions of Vim do exist, but will not be covered in this tutorial

Vim Tutor Vim has a tutor to teach you many of the commands that can be used in Vim. Vim tutor contains many additional commands not covered in this workshop. This workshop focuses on the commands most commonly used in CS 331. To use the tutor, type vimtutor and press enter. Note that you can launch the Vim tutor from within any directory in Dijkstra.

Launching Vim Editing an existing file Type vim followed by the program name and hit enter Example: vim Stack.java Creating a new file Similar to editing an existing file, type vim followed by the desired program name and hit enter Example: vim Stack2.java

Vim Navigation Vim is completely a text editor, so it will not respond to any input in the mouse. You cannot click to a location in your code, Vim will simply ignore it. To navigate, use either the arrow keys or the h, j, k, and l keys h is (left) j is (down) k is (up) l is (right)

Vim File Commands Vim has a few basic file commands. These commands are all executed preceded by a : and press enter after the command w: save file q: close file The q command will only work when you have not made any changes to the file since you saved it. To close a file you have made changes to, use q! or wq q!: close file without saving wq: save and close file

Vim File Commands Practice Open the Stack.java file (or any other file) Type :w and press enter. This saves the file. Type :q! and press enter. This closes the file. Open the Stack.java file again Type :wq and press enter. This saves and closes the file in one line.

Vim Insertion Mode To actually edit files, Vim has a special mode called the insertion mode. Switch to insertion mode by pressing i Switch out of insertion mode by pressing the escape key

Editing in Vim Navigation in insert mode is the same as before: use the arrow keys or h,j,k, and l keys to navigate through your code Typed text will appear directly to the left of the cursor, likewise pressing either backspace or delete will delete the character to the left of the cursor

Vim Highlighting Features Keywords such as public, int, this, class, etc. show up in green Variable values (ex: 0, null, hi ) are shown in red New is yellow Comments are blue

Vim Editing Features Move your cursor to the right of a curly bracket to have the matching one be highlighted blue Vim does not automatically indent your code, however, if you are typing in an indented line, hitting enter will indent the next line by the same amount

Vim Editing Practice Try creating a simple HelloWorld file using the techniques and features discussed. Navigate through the file to see how Vim keeps track of matching pairs of brackets.

Copy and Paste in Vim Before you try to copy and paste, exit insertion mode. Select the text you want to copy by moving the cursor to the beginning of the text, pressing v (visual), and then using the arrow keys to highlight the desired text Copy this text using y (yank) (or press d to cut) Move to where you want to paste using the arrow keys and press p (paste)

Vim Copy and Paste Practice Copy the main method from the HelloWorld file from the earlier example and paste it into a new java file. Save and close both files.

Vim Command Summary Vim FileName.java Open or create a file to edit :w + Enter save file :q + Enter quit, close file :q! + Enter close file without saving :wq + Enter save and close file i start insertion mode v visual, select a section of text y yank, copy d delete, cut p - paste

Emacs Emacs was first released 1976 as a set of Editor MACroS for the TECO editor Emacs is a free and open source software Emacs is entirely a text editor, it has no graphics whatsoever. Graphic versions of Emacs do exist, but will not be covered in this tutorial

Launching Emacs Editing an existing file Type emacs followed by the program name and hit enter Example: emacs Stack.java Creating a new file Similar to editing an existing file, type emacs followed by the desired program name and hit enter Example: emacs Stack2.java

Emacs Tutor Emacs has a tutor to teach you many of the commands that can be used in Emacs. Emacs tutor contains many additional commands not covered in this workshop. This workshop focuses on the commands most commonly used in CS 331. To use the tutor launch Emacs by typing emacs and pressing enter Press the control (Ctrl) key and h, followed by t to launch the tutorial

Navigation in Emacs Emacs is completely a text editor, so it will not respond to any input in the mouse. You cannot click to a location in your code, Vim will simply ignore it. Navigate in Emacs using the arrow keys You can also use the Ctrl key + p, b, f, and n to navigate p previous (line above) n next (line below) f forward (to the right) b back (to the left)

Emacs File Commands To close a file, press Ctrl X, followed by Ctrl C Emacs will ask you if you want to save. Press y to save, n to not save, or Ctrl + h for help If you say no, then Emacs will ask you again. This time you must type either yes or no To save a file, press Ctrl X, followed by Ctrl S

Emacs File Commands Practice Open the Stack.java file (or any other file) Type Ctrl + X, followed by Ctrl + S. This saves the file. Type Ctrl + X, followed by Ctrl + C. This closes the file. Choose whether or not to save your file when prompted

Editing in Emacs Unlike Vim, emacs has only one mode (i.e. there is no separate insertion mode), so whatever you type will appear in the file Typed text will appear directly to the left of the cursor, likewise pressing either backspace will delete the character to the left of the cursor Note that pressing delete does not delete characters you have typed. You must use backspace

Emacs Highlighting Keywords such as public, this, class, new, etc. show up in light blue Variable types are shown in green Comments are shown in red Variable names are yellow Null and external classes are purple Method names are blue Note that method names are only in blue for classes not using generics (<E>, etc.) Method names in classes using generics are in yellow Constructors are not highlighted

Emacs Editing Features When you type a closing curly bracket, Emacs will briefly move the cursor to the opening curly bracket matching it Emacs does not automatically indent your code, however, if you are typing in an indented line, hitting enter will indent the next line by the same amount

Emacs Editing Practice Try creating a simple HelloWorld file using the techniques and features discussed. Try adding lines of the code to the file to explore all of the editing features of Emacs

Copy and Paste in Emacs To Copy: Press Ctrl space Move the cursor until all the text you want is highlighted When you highlight this text, you must include one extra character at the end or Emacs will cut off the final character Then press Esc, followed by w

Copy and Paste in Emacs To Paste: To paste press Ctrl + y The text will appear after the cursor

Emacs Copy and Paste Practice Copy the main method from the HelloWorld file from the earlier example and paste it into a new java file. Save and close both files.

Emacs Command Summary Emacs FileName Open or create a file to edit Ctrl + X, Ctrl + C Close a file. Use menu options to decide whether or not to save Ctrl + X, Ctrl + S Save a file Ctrl + Space Start copy Esc + w End copy Ctrl + Y - Paste

JUnit JUnit, or java unit, tests allow you to test how your code runs under various situations Unit tests get their own java file, usually called TestFile.java (so unit tests for Stack.java would be in TestStack.java)

JUnit File Setup The building blocks of every JUnit class: Import statement: import junit.framework.*; Class declaration: public class TestFile extends TestCase{ Default constructor: public TestFile(String name) { super(name); }

JUnit File Setup Example TestStack.java Declaring variables at the top of the file is usually helpful as it allows you to use them in all of your unit tests.

JUnit Methods All of your methods should begin with test, otherwise JUnit will not run them. The return type should be void and the methods should take no arguments Example: public void testempty() { As with most other Java files, you can create variables, including instances of the class you are testing within your methods, and call methods on those variables

JUnit assertequals The assertequals method will run a method from the class you are testing, and compare it against the expected return value of that method (that you provide) Arguments (in order): String: the method label, something describing what you are testing String, int, double, etc.: the expected return value of the method being tested Method: the method you want to test

JUnit assertequals Example

Running JUnit Tests Compile your main class and your test class normally Run your test class by typing scons tests and hitting enter If all your tests pass the output will look something like this:

JUnit Test Errors Red: Class where test failed Orange: Method where test failed Green: Label and expected and actual values of failed test Blue: Exact location where failure occurred (file:line number) By reading the top line: An error occurred in the testempty method of the TestStack class. The Pop Test failed. The expected return value was 0, but the actual return value was -1.

Questions?