View this PageEdit this PageAttachments to this PageHistory of this PageHomeRecent ChangesSearch the SwikiHelp Guide
Hotspots: Admin Pages | Turn-in Site |
Current Links: Cases Final Project Summer 2007

Discussion 4 - Manabu Shimobe

Sum2003 Midterm Review: Testing and Refactoring

1. What is SUnit and why would you want to use it?
SUnit is a Testing framework for creating and running unit tests automatically in Smalltalk.
Sunit allows programmers to check results against expected results and report which test is broken. Sunit can be used for regression testing to see whether your changes to your code broke old functionality.
The idea of Extreme Programming -> Create unit test before the code. It will help you understand what the code must do.

(Example:)
If you want to test your class(named X), then write a new class of the form:
(Assume you have a class named X)
TestCase subclass: #TestX
instanceVariableNames: 'testVariable'
classVariableNames: ''
poolDictionaries: ''
category: 'SUnitTests'

Before starting a test, your test class usually must be prepared for it. Create the method setUp. In this case,
sets testVariable to 5 so that we can test simple Arithmetic operations on Integers.

TestX>>setUp
testVariable := 5.

Now let's test whether addition works(create a method of the form testXxxx.In this case -> testAddition(Xxxx is functionality in class X))

TestX>>testAddition
self assert: (testVariable + 2 = 7).
self deny: (testVariable + 1 = 3).

Both assert: and deny: expect Boolean as answer. If assert: receives false or deny: recieves true, then the test is considered as failed and an error is noted.

2. What is refactoring and why would you want to do it?
Refactoring basically means making your code simpler and elegant so that your program becomes easier to reuse or maintain(Of course, you have to preserve the behavior of your program). Refactoring is the key part of Extreme Programming.

3. Name one kind of refactoring and the problem it is supposed to solve
Move method is one kind of refactoring. When a method exists in one class but uses data found in another class, we can use this Move method to solve the problem. To solve this problem, we should move the method to the class that has the data the method works on.

(Other kinds of refactoring)
Getting rid of duplicate code.
Extract class.
Extract method.
Extract method process.
Move attributes.
Replace conditional with polymorphism.

Link to this Page