mirror of
https://github.com/emilybache/GildedRose-Refactoring-Kata.git
synced 2025-12-12 12:22:12 +00:00
Improving the documentation, especially around text-based testing
This commit is contained in:
parent
2e5a38d000
commit
bf68436e11
@ -1,10 +1,34 @@
|
||||
This Kata was originally created by Terry Hughes (http://twitter.com/#!/TerryHughes). It is already on GitHub as "GildedRose", a sample project for C#. I could have forked it again, but I thought other language users might not want to download a whole C# project environment. In this repository are starting code samples for Java, Python and C++.
|
||||
This Kata was originally created by Terry Hughes (http://twitter.com/#!/TerryHughes). It is already on GitHub as "GildedRose", a sample project for C#. I could have forked it again, but I thought other language users might not want to download a whole C# project environment. In this repository are starting code samples for Java, Python, Ruby, C# and C++.
|
||||
|
||||
See also http://iamnotmyself.com/2011/02/13/refactor-this-the-gilded-rose-kata/
|
||||
|
||||
================
|
||||
Gilded Rose Kata
|
||||
================
|
||||
====================
|
||||
How to use this Kata
|
||||
====================
|
||||
|
||||
The simplest way is to just clone the code and start hacking away improving the design. I strongly advise you that you'll need some tests if you want to make sure you don't break the code in the process though.
|
||||
|
||||
You could write some unit tests yourself, using the Kata Background Reading (below) to identify suitable test cases. I've provided a failing unit test in a popular test framework as a starting point for most languages.
|
||||
|
||||
Alternatively, use the "Text-Based" tests provided in this repository. (Read more about that in the next section)
|
||||
|
||||
Whichever testing approach you choose, the idea of the exercise is to do some deliberate practice, and improve your Refactoring skills. The idea is not to re-write the code from scratch, but rather to practice taking small steps, running the tests often, and incrementally improving the design.
|
||||
|
||||
==================
|
||||
Text-Based Testing
|
||||
==================
|
||||
|
||||
This is a testing approach which is very useful when refactoring legacy code. The basic idea is to create tests that use the text which the code produces. Before you change the code, you run it, and save the output as a "Golden Copy". Then after you change the code, you run it again, and compare the output against the Golden Copy. Any differences, and the test fails.
|
||||
|
||||
It's basically the same idea as "assertEquals(expected, actual)" in a unit test, except the text you are comparing is typically much longer, and the "expected" value is saved from actual output, rather than being defined in advance.
|
||||
|
||||
Typically a piece of legacy code may not produce suitable textual output from the start, so you may need to modify it before you can write your first text-based test. That could involve inserting log statements into the code, or just writing a "main" method that executes the code and prints out what the result is afterwards. It's this latter approach we are using here to test GildedRose.
|
||||
|
||||
The Text-Based tests in this repository are designed to be used with the tool "TextTest" (http://texttest.org). This tool helps you to organize and run text-based tests. There is more information in the README file in the "texttests" subdirectory.
|
||||
|
||||
===================================
|
||||
Gilded Rose Kata Background Reading
|
||||
===================================
|
||||
|
||||
Hi and welcome to team Gilded Rose. As you know, we are a small inn with a prime location in a prominent city ran by a friendly innkeeper named Allison. We also buy and sell only the finest goods. Unfortunately, our goods are constantly degrading in quality as they approach their sell by date. We have a system in place that updates our inventory for us. It was developed by a no-nonsense type named Leeroy, who has moved on to new adventures. Your task is to add the new feature to our system so that we can begin selling a new category of items. First an introduction to our system:
|
||||
|
||||
|
||||
37
GildedRose/texttests/README
Normal file
37
GildedRose/texttests/README
Normal file
@ -0,0 +1,37 @@
|
||||
This folder contains Text-Based tests for the GildedRose Refactoring Kata.
|
||||
|
||||
These tests are designed to be used with the open source testing tool "TextTest", available from http://texttest.org You can run them without it too though, see below.
|
||||
|
||||
========================
|
||||
Running without TextTest
|
||||
========================
|
||||
|
||||
This should be perfectly possible, but is probably less convenient than using TextTest.
|
||||
|
||||
Write a script that will execute the SUT (see "config.gr" for details of the executables), giving the commandline options listed in "options.gr". Collect the output from standard output in a file, and diff that against the golden copy "stdout.gr". Any diff is a test failure.
|
||||
|
||||
=====================
|
||||
Running with TextTest
|
||||
=====================
|
||||
|
||||
- Install TextTest (see http://texttest.org)
|
||||
- set $TEXTTEST_HOME environment variable to point at the "texttests" folder
|
||||
- run texttest using a command like "python texttest.py -a gr"
|
||||
|
||||
This should start the GUI for the TextTest tool.
|
||||
|
||||
Each test case has it's own subdirectory. The name of the directory is the name of the test - in this case "ThirtyDays". The "Golden Copy" of the output for that test case is kept in that directory. In this case we have three files:
|
||||
|
||||
stderr.gr - the expected output to Standard Error (stderr)
|
||||
stdout.gr - the expected output to Standard Output (stdout)
|
||||
options.gr - the options to give on the command line when you run the System Under Test (SUT)
|
||||
|
||||
In the directory above, there are configuration files for TextTest:
|
||||
|
||||
config.gr - this tells TextTest where to find the SUT executable, and sets up options for how it runs the SUT and interprets the output.
|
||||
environment.gr - this file lists environment variables that will be set before TextTest runs the SUT. This is especially important for Java applications, that must set the CLASSPATH environment variable in order to run properly.
|
||||
testsuite.gr - lists the constituent test cases of this suite. Change the order of the entries here to change the order they appear in the TextTest GUI.
|
||||
|
||||
To run a test, click on it in the GUI and select "Run". TextTest will run it in a temporary (sandbox) directory and report the results. If the test fails, you can double click on a file to see the diff against the Golden Copy.
|
||||
|
||||
|
||||
4
README
4
README
@ -1,6 +1,8 @@
|
||||
Can you refactor? In really small steps? Can you turn some, frankly, ugly code into a paradigm of elegant, readable, extensible design?
|
||||
|
||||
This is a collection of starting files for when practicing refactoring.
|
||||
|
||||
Contents so far:
|
||||
|
||||
Tennis Kata in Java, Python and C++.
|
||||
Gilded Rose Kata in Java, Python and C++. (a C# version is already available on github)
|
||||
Gilded Rose Kata in C++, C#, Java, Python and Ruby. (a C# version together with a starting project is already available on github)
|
||||
Loading…
Reference in New Issue
Block a user