t-unit: Tcl Unit Test Package
description
Transcript of t-unit: Tcl Unit Test Package
t-unit: Tcl Unit TestPackage
Automated Unit Test PackageFor Tcl ProceduresFinal Presentation
Joseph BoyleLoyola Marymount University
Loyola Marymount University 2
Introduction
Understand how Agile Software practices can be used in a scripting language environment
How Agile practices can be applied in an industry that is big on up-front design
Create a project that is open source
Final PresentationIntroductionUpdated: 25-Nov-2006
Loyola Marymount University 3
Related Work
Many key players in the Agile movement Kent Beck
Extreme Programming Martin Fowler
Refactoring, Continuous Integration Andrew Hunt and David Thomas
The Pragmatic Programmer
Tcl Scripting Language Created by John Ousterhout in early 1980’s at Berkeley
Final PresentationRelated WorkUpdated: 25-Nov-2006
Loyola Marymount University 4
State of Software Development
Need to get away from plan-driven approach Can’t see the complexity of the software ahead of
time The culture must be ready for change! Start with a vision and a set of principles that
defines what needs to be accomplished From these principles we can derive a set of
working practices
Final PresentationState of SW DevelopmentUpdated: 25-Nov-2006
Loyola Marymount University 5
Agile Culture
Disciplined in approach and goal focused Responsible for one’s work Leaders that can help others succeed Highly collaborative team that can embrace
differences between personalities and roles and strive for success
Feel comfortable communicating with the team Keep the product simple to solve only the problem
at hand Courage to speak up when things are going bad
Final PresentationAgile CultureUpdated: 25-Nov-2006
Loyola Marymount University 6
Agile Principles
Continual Refinement Enhances the ability to change with the customer’s needs
Working Product at All Times The goal of software developers is to ship software. Keep
the software as close as possible to a shipping state. Continual investment in and emphasis on Design
Design decisions and changes are made every day by every member of the team
Extends the life of the product Value defect prevention over defect detection
Prevent defects to save yourself the headaches later on
Final PresentationAgile PrinciplesUpdated: 25-Nov-2006
Loyola Marymount University 7
Design and Documentation Keep the design simple
Design and code for what is needed today Consider designing reusable software for future projects
UML offers a wide variety of tools to document the design Since Tcl is a scripting language, a sequence diagram can
typically be used when designing a module Extraction software such as JavaDoc can be useful
for documenting software Tcl has its own documentation utility known as AutoDOC
Developed by Andreas Kupries in 2001 as an extension to the language
Final PresentationAgile PracticesUpdated: 25-Nov-2006
Loyola Marymount University 8
The Customer
Always have the customer's input when creating software Responsible for the requirements Ability to pick which features are most important,
and therefore, should be developed first
Final PresentationAgile PracticesUpdated: 25-Nov-2006
Loyola Marymount University 9
Coding Conventions
Makes the code easy to read, especially if a new team member arrives
Ray Johnson of Sun Microsystems created a Tcl style guide for the Tcl programming language Using these coding conventions in conjunction
with the AutoDOC utility makes Tcl source code well commented and easy to read
Final PresentationAgile PracticesUpdated: 25-Nov-2006
Loyola Marymount University 10
Paired Programming Paired programming involves two people sitting at one computer
where each person can sit comfortably and work can get done. Keep one another on task Refine the system Come up with ideas When one partner is stuck the other can take over, lowering
the stress level Hold each other responsible for following the other practices
the team is following Downsides of Paired Programming
Watching another person type can be painful Many companies consider paired programming a waste of a
resource
Final PresentationAgile PracticesUpdated: 25-Nov-2006
Loyola Marymount University 11
Code Reviews
Code reviews in conjunction with paired programming allow for the whole team to own the code Allow for the team to learn and share ideas about the
project
There are downsides of code reviews without paired programming Typically logic errors are missed
A combination of paired programming and code reviews will lead to better defect prevention
Final PresentationAgile PracticesUpdated: 25-Nov-2006
Loyola Marymount University 12
Iterative and Incremental Development
“Plan a little, do a little, learn a little.” By developing the software incrementally, the
software can stay in a releasable state Putting in the most important features first,
the software could theoretically be released to the customer if they decide that some of the features initially envisioned are no longer necessary
Final PresentationAgile PracticesUpdated: 25-Nov-2006
Loyola Marymount University 13
Continuous Integration
Frequent integration insures that modules that must fit together will
Automate the build with unit tests to detect errors as soon as possible An Ant build can be created for this
A single source repository keeps the necessary items for a build together
Final PresentationAgile PracticesUpdated: 25-Nov-2006
Loyola Marymount University 14
Sample Test Target
<!--
< Define the test target (runs the unit tests)
< -->
<target name="test" depends="compile">
<exec dir="${build.scripts.dir}/unitTests“ executable="tclsh">
<arg line="unitTestsAll.tcl"/>
</exec>
</target>
Final PresentationAgile PracticesUpdated: 25-Nov-2006
Loyola Marymount University 15
Refactoring
Refactoring can improve the structure of code without changing its behavior
Martin Fowler wrote a whole book on refactoring and offers wide variety of refactorings available Most can only be applied to Object Oriented Languages Sample refactorings for scripting languages:
Add a parameter Consolidate Conditional Expression Extract Method
Final PresentationAgile PracticesUpdated: 25-Nov-2006
Loyola Marymount University 16
Unit Testing
Prevents defects from ending up in software Gives confidence that the product is behaving
as expected Tcl had two unit test frameworks available:
tcltest – does not use the xUnit framework TclTkUnit – does not report results sufficiently
“t-unit” was developed to be a better unit test framework for Tcl
Final PresentationAgile PracticesUpdated: 25-Nov-2006
Loyola Marymount University 17
t-unit
Provides an automated unit test framework Modeled after the “JUnit” Java test suite All calls are “asserts”; e.g.:
“assertEqual” checks for equal results “assertTrue” checks for result of boolean TRUE . . .and so on. . .
Final PresentationAgile PracticesUpdated: 25-Nov-2006
t-unit “Class” DiagramUpdated: 25-Nov-2006
File
Test Suite
Report
«creates»
«examines»Procedure
PackageUnder Test
Expression«calls»
«input, expected»
Test Case
+ reason: String Test Result
Pass Fail
«result»
{complete, discrete}
Package t-unit
t-unit::assertXXXX«abstract»
t-unit::testHarness«calls»
t-unit::assertEquals
t-unit::assertEqualsReal
t-unit::assertEqualsList
t-unit::assertEqualsArray t-unit::assertNotEquals
t-unit::assertFalse
t-unit::assertTrue
«test function»
«reads»
«writes»
user
«runs»
Loyola Marymount University 19
Sample Test CaseTUnit Process ModelTest Case File DescriptionUpdated: 27-Oct-2006
t-unit::assertEquals 12.34 12.34 | PASS | OKt-unit::assertEquals "hello“ "hello” | PASS | OKt-unit::assertEquals "hello“ "world“ | FAIL | NOT_EQUALt-unit::assertEquals 2 2 | PASS | OKt-unit::assertEquals 2 3 | FAIL | NOT_EQUALt-unit::assertEquals 12345 12345 | PASS | OKt-unit::assertEquals 12345 12345.0 | FAIL | ARG_MISMATCHt-unit::assertEquals TRUE TRUE | PASS | OKt-unit::assertNotEquals TRUE FALSE | PASS | OKt-unit::assertNotEquals “hello” “world” | PASS | OKt-unit::assertEqualsList {1 2 3} {1 2 3} | PASS | OKt-unit::assertEqualsArray A1 A2 | PASS | OKt-unit::assertEquals [samplePackage::addOne 1] 2 | PASS | OK
Usage notes:1. Vertical bars required as shown2. Whitespace required as shown3. Optional third parameter (not shown) allows tailoring of response message for each assertion4. Either parameter (or both parameters) may be a Tcl “list” data type
• List can contain a procedure name and its arguments• Allows testing of procedures, not just values (real strength of this package)• Enclose lists in curly braces within test file, or define globally prior to running t-unit
(may be defined as part of automated test suite)• List may comprise a procedure and its argument list
Final PresentationTest Case File DescriptionUpdated: 25-Nov-2006
Loyola Marymount University 20
Use Available Tools A wide variety of tools at our disposal
Text editors that offer syntax highlighting Office suites for presentations and UML documents
Configuration Management (CM) System Keep track of every change in source code and
documentation Allows for continuous integration to be seamless Subversion, CVS
Eclipse Open Development Platform Text editor Build and unit testing Integrated GUI for CM
Final PresentationAgile PracticesUpdated: 25-Nov-2006
Loyola Marymount University 21
TUnit TUnit is a plug-in for the Eclipse IDE. TUnit makes use of the t-unit
package that was developed for the Tcl programming language. Features:
Tcl Perspective Tcl Project Wizard – creates tcl projects with t-unit included Tcl Package Creator – creates packages within the project Tcl File Creator – creates tcl files with AutoDOC comments in place Tcl File Editor – allows for syntax highlighting, auto indentation, and content
assistance (i.e. completion of commands) Preferences menu Namespace Explorer – lists packages and files within each package; can be
used to verify that Tcl coding standards are being followed Execution of t-unit scripts
A set of unit tests is also available to test the TUnit plug-in Demonstration
Final PresentationAgile PracticesUpdated: 25-Nov-2006
Loyola Marymount University 22
TUnit Extension The Eclipse Dynamic Languages Toolkit (DLTK)
project was created to develop a framework for tool vendors, researchers, and end-users who rely on dynamic languages such as Tcl
Xored Software Inc. was behind the plug-in and they are developing the project in Russia
Eclipse DLTK did not include a unit test framework as part of the plug-in TUnit extension was born Offered to create this part of the plug-in using the t-unit
package Demonstration
Final PresentationAgile PracticesUpdated: 25-Nov-2006
Loyola Marymount University 23
Future Research Over time, more practices will be added to Agile to
make the development process even more seamless
The future of TUnit and the TUnit extension is still up in the air TUnit has been released as version 1.0.0 No bugs reported to date via the Google Code repository
TUnit extension could see additional revisions The Eclipse DLTK project is interested in adding the tcltest
framework to the TUnit extension Code is written to do this fairly easily Looking at a date in January 2007
Final PresentationFuture ResearchUpdated: 25-Nov-2006
Loyola Marymount University 24
Conclusions
Agile is not going away but getting stronger
More and more it is being accepted as a valid process for creating software
Not all the practices need to be followed: come up with a set that fits the team’s needs
Final PresentationFuture ResearchUpdated: 25-Nov-2006
Loyola Marymount University 25
Source Code TUnit has a homepage at: http://tunitplugin.googlepages.com
Project can be downloaded from here along with documentation and screenshots
Source code repository for the paper, this presentation, TUnit and the TUnit unit tests at: http://code.google.com/p/t-unit/
Eclipse DLTK considering putting the extension of TUnit in their next milestone release The source code is located in Loyola Marymount’s CVS for now
but could move into the Eclipse DLTK repository next year Could not use the Google repository because the Eclipse Public
License is not available Can also download the project at the TUnit homepage
Final PresentationFuture ResearchUpdated: 25-Nov-2006
Loyola Marymount University 26
Questions or Comments