mad computer science: testing cobol with rspec
DESCRIPTION
Really? COBOL? Yes, really. There are lots of enterprisey things that just aren't test-driven because of a lack of tooling. COBOL is one of them and it misses out on all the benefits of TDD. But it doesn't have to. In this session I will show how I used RSpec to test-drive MicroFocus COBOL on Windows and demo it with a simple kata. In the process you'll learn a smattering of COBOL and how to apply the same basic technique to test-drive other difficult to test technologies.TRANSCRIPT
Mad Computer ScienceTesting COBOL With RSpec
@guyroyse
About Me
2
Guy RoyseDevelopment Competency LeadApplication Development Center
Likes TDD, Pairing, Polyglot Programming, Piña Coladas, Walks in the Rain
Dislikes Coding Alone, Complexity, Being Confused for Hagrid
3
COBOLJavaRubyTDD
RSpec
4
Test COBOL
5
About COBOL
6
CompletelyObsoleteBusinessOrientedLanguage
7
** No affiliation with GEICO is intended or implied. All rights reserved. Look both ways before crossing the street. Vote early and vote often.
**
8
"COBOL has almost no fervent enthusiasts. As a programming tool, it has
roughly the sex appeal of a wrench."
Charles Petzold
9
A Simple Application
The Data The Code
10
PhoneValidator
AddressValidator
ContactValidatorContact
AddressPhone
Java Data Implementation
11
public class Contact { private String name; private Phone home; private Phone cell; private Address address;
public String getName() { return name }; public void setName(String name) { this.name = name; }
/* etc. */}
COBOL Data Implementation
12
01 CONTACT. 05 NAME PIC X(30). 05 HOME-PHONE. 10 HOME-AREA-CODE PIC 9(3). 10 HOME-EXCHANGE PIC 9(3). 10 HOME-PHONE-NUMBER PIC 9(4). 05 CELL-PHONE. 10 CELL-AREA-CODE PIC 9(3). 10 CELL-EXCHANGE PIC 9(3). 10 CELL-PHONE-NUMBER PIC 9(4). 05 ADDRESS. 10 STREET PIC X(30). 10 CITY PIC X(20). 10 STATE PIC X(2). 10 ZIP-CODE PIC X(5).
Java Code Implementation
13
public class ContactValidator { private PhoneValidator phoneValidator; private AddressValidator addressValidator;
public void validate(Contact contact) { validateName(contact.getName); phoneValidator.validate(contact.getHome()); phoneValidator.validate(contact.getCell()); addressValidator.validate(contact.getAddress()); }
private void validateName(String name) { /* validates name */ }
}
COBOL Code Implementation
14
IDENTIFICATION DIVISION. PROGRAM-ID. CONTACT-VALIDATOR.
PROCEDURE DIVISION USING CONTACT.
MAIN. CALL PHONE-VALIDATOR USING HOME-PHONE. CALL PHONE-VALIDATOR USING CELL-PHONE. CALL ADDRESS-VALIDATOR USING ADDRESS. PERFORM VALIDATE-NAME. GOBACK
VALIDATE-NAME.* VALIDATE NAME
15
16
COBOL is Just as Testable as Java
COBOLRuby
Eternity
17
contactspec.rb
ETERNITY.CBL
CONTACT.CBL
command.txt
input.txt
output.txt
eternity.rb
18
Demo!
Image Credits
19
http://www.flickr.com/photos/justin_case/1525042316http://www.flickr.com/photos/cbmd/2475626473
http://www.flickr.com/photos/kc-bike/2398970429http://www.flickr.com/photos/7603557@N08/454618030
http://www.flickr.com/photos/pennuja/5386712834http://www.flickr.com/photos/blackeycove/3997170938