mirror of
https://github.com/emilybache/GildedRose-Refactoring-Kata.git
synced 2025-12-11 20:02:09 +00:00
make texttest easier to use
This commit is contained in:
parent
5d4b4ab839
commit
02d4c1db4a
@ -22,13 +22,7 @@ Whichever testing approach you choose, the idea of the exercise is to do some de
|
|||||||
|
|
||||||
## Text-Based Approval Testing
|
## Text-Based Approval Testing
|
||||||
|
|
||||||
This is a testing approach which is very useful when refactoring legacy code. Before you change the code, you run it, and gather the output of the code as a plain text file. You review the text, and if it correctly describes the behaviour as you understand it, you can "approve" it, and save it as a "Golden Master". Then after you change the code, you run it again, and compare the new output against the Golden Master. Any differences, and the test fails.
|
This code comes with comprehensive tests that use this approach. For information about how to run them, see the [texttests README](https://github.com/emilybache/GildedRose-Refactoring-Kata/tree/master/texttests)
|
||||||
|
|
||||||
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 approval test. One way to do that is to write a "main" method that executes the code and prints out what the result is afterwards.
|
|
||||||
|
|
||||||
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.
|
|
||||||
|
|
||||||
## Get going quickly using Cyber-Dojo
|
## Get going quickly using Cyber-Dojo
|
||||||
|
|
||||||
|
|||||||
@ -1,28 +1,22 @@
|
|||||||
# TextTest regression tests
|
# TextTest regression tests
|
||||||
|
|
||||||
This folder contains Text-Based Approval tests for the GildedRose Refactoring Kata.
|
This folder contains Text-Based Approval tests for the GildedRose Refactoring Kata. They are fairly comprehensive and well worth using if you'd prefer to go straight to the refactoring without writing your own tests first.
|
||||||
|
|
||||||
These tests are designed to be used with the open source testing tool "TextTest", available from [http://texttest.org](http://texttest.org).
|
These tests are designed to be used with the open source testing tool "TextTest", available from [http://texttest.org](http://texttest.org).
|
||||||
|
|
||||||
## Step-by-step instructions
|
## Install TextTest
|
||||||
|
|
||||||
These tests are quite good and it's worth trying them.
|
There are install instructions on the [texttests website](http://texttest.sourceforge.net/index.php?page=documentation_4_0&n=install_texttest). If you are happy to run without the Graphical User Interface, then you only need python3 and pip:
|
||||||
|
|
||||||
### Install TextTest
|
|
||||||
|
|
||||||
There are install instructions on [texttests website](http://texttest.sourceforge.net/index.php?page=documentation_4_0&n=install_texttest). If you are happy to run without the Graphical User Interface, then you only need python3 and pip:
|
|
||||||
|
|
||||||
> pip install texttest
|
> pip install texttest
|
||||||
|
|
||||||
### Configure language version
|
## Configure language version
|
||||||
|
|
||||||
Before you can run the tests you need to tell texttest which language version of GildedRose you plan to refactor. Open the file 'config.gr' and edit it. Several languages are supported. All lines starting with '#' are comments in this file. Find the lines referring to the language you want, and uncomment them.
|
Before you can run the tests you need to tell texttest which language version of GildedRose you plan to refactor. Open the file 'config.gr' and edit it. Several languages are supported. All lines starting with '#' are comments in this file. Find the lines referring to the language you want, and uncomment them. (Note some languages like Java need several lines uncommented)
|
||||||
|
|
||||||
Note: by default the 'python' version is selected. You'll need to comment those lines out if you have chosen a different langauge.
|
|
||||||
|
|
||||||
While you're here, change the settings for editor and diff program to match your preferences. By default it uses 'subl' and 'meld'. It will accept any editors or diff programs that you can run from the command line.
|
While you're here, change the settings for editor and diff program to match your preferences. By default it uses 'subl' and 'meld'. It will accept any editors or diff programs that you can run from the command line.
|
||||||
|
|
||||||
### running TextTest
|
## running TextTest
|
||||||
|
|
||||||
Start texttest from the folder above the one this file is in. Texttest detects the current working directory and uses that as the variable $TEXTTEST_HOME in the config.gr file.
|
Start texttest from the folder above the one this file is in. Texttest detects the current working directory and uses that as the variable $TEXTTEST_HOME in the config.gr file.
|
||||||
|
|
||||||
@ -30,9 +24,7 @@ Start texttest from the folder above the one this file is in. Texttest detects t
|
|||||||
> cd /home/ec2-user/workspace/GildedRose-Refactoring-Kata
|
> cd /home/ec2-user/workspace/GildedRose-Refactoring-Kata
|
||||||
> texttest &
|
> texttest &
|
||||||
|
|
||||||
This should start the GUI for the TextTest tool.
|
This should start the GUI for the TextTest tool. Select the test case "ThirtyDays" and press the "Run" button. This will open a new 'runner' window for each test run.
|
||||||
|
|
||||||
From the GUI, select the test case "ThirtyDays" and press the "Run" button. This will open a new 'runner' window for each test run.
|
|
||||||
|
|
||||||
If the texttest GUI doesn't work, or you prefer to use the command line, use this instead:
|
If the texttest GUI doesn't work, or you prefer to use the command line, use this instead:
|
||||||
|
|
||||||
@ -40,16 +32,15 @@ If the texttest GUI doesn't work, or you prefer to use the command line, use thi
|
|||||||
|
|
||||||
That will run all the test cases it finds and report the results.
|
That will run all the test cases it finds and report the results.
|
||||||
|
|
||||||
|
|
||||||
## Running without TextTest
|
## Running without TextTest
|
||||||
|
|
||||||
This should be perfectly possible, but is probably less convenient than using TextTest.
|
This should be perfectly possible, but is probably less convenient than using TextTest.
|
||||||
|
|
||||||
Write a script that will execute the system under test (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.
|
Write a script that will execute the system under test (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.
|
||||||
|
|
||||||
## TextTest test cases
|
## Explaining TextTest test cases
|
||||||
|
|
||||||
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:
|
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 Master" 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)
|
- __stderr.gr__ - the expected output to Standard Error (stderr)
|
||||||
- __stdout.gr__ - the expected output to Standard Output (stdout)
|
- __stdout.gr__ - the expected output to Standard Output (stdout)
|
||||||
@ -65,4 +56,11 @@ To run a test, click on it in the GUI and select "Run". TextTest will run it in
|
|||||||
|
|
||||||
If you run into difficulties with TextTest, there is documentation available on [texttest.org](http://texttest.org), or you can ask a question on the [mailing list](https://lists.sourceforge.net/lists/listinfo/texttest-users).
|
If you run into difficulties with TextTest, there is documentation available on [texttest.org](http://texttest.org), or you can ask a question on the [mailing list](https://lists.sourceforge.net/lists/listinfo/texttest-users).
|
||||||
|
|
||||||
|
## Introduction to Text-Based Approval Testing
|
||||||
|
|
||||||
|
This is a testing approach which is very useful when refactoring legacy code. Before you change the code, you run it, and gather the output of the code as a plain text file. You review the text, and if it correctly describes the behaviour as you understand it, you can "approve" it, and save it as a "Golden Master". Then after you change the code, you run it again, and compare the new output against the Golden Master. 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 approval test. One way to do that is to write a "main" method that executes the code and prints out what the result is afterwards. Each language version has implemented a texttest 'fixture' that does this. It runs the GildedRose 'update_quality' method once each day for 30 days, printing the item state each day.
|
||||||
|
|
||||||
|
|||||||
@ -1,3 +1,3 @@
|
|||||||
# If your .class files are somewhere else, add the path to the list
|
# If your .class files are somewhere else, add the path to the list
|
||||||
CLASSPATH:${TEXTTEST_CHECKOUT}/Java:${TEXTTEST_CHECKOUT}/Java/bin
|
CLASSPATH:${TEXTTEST_HOME}/Java:${TEXTTEST_HOME}/Java/bin
|
||||||
PERL5OPT:-I${TEXTTEST_CHECKOUT}/perl
|
PERL5OPT:-I${TEXTTEST_HOME}/perl
|
||||||
Loading…
Reference in New Issue
Block a user