mirror of
https://github.com/emilybache/GildedRose-Refactoring-Kata.git
synced 2025-12-11 20:02:09 +00:00
Improve texttest documentation
Specifically make it easier to test the Java version. Added a test rig so you can use gradle to run the java version
This commit is contained in:
parent
615ad96ea4
commit
755ed77692
@ -13,3 +13,7 @@ For e.g. 10 days:
|
||||
```
|
||||
./gradlew -q text --args 10
|
||||
```
|
||||
|
||||
## Run the TextTest approval test that comes with this project
|
||||
|
||||
There are instructions in the [TextTest Readme](https://github.com/emilybache/GildedRose-Refactoring-Kata/blob/main/texttests/README.md) for setting up TextTest. What's unusual for the Java version is there are two executables listed in [config.gr](https://github.com/emilybache/GildedRose-Refactoring-Kata/blob/main/texttests/config.gr) for Java. One uses Gradle wrapped in a python script, the other relies on your CLASSPATH being set correctly in [environment.gr](https://github.com/emilybache/GildedRose-Refactoring-Kata/blob/main/texttests/environment.gr).
|
||||
|
||||
14
Java/texttest_rig.py
Normal file
14
Java/texttest_rig.py
Normal file
@ -0,0 +1,14 @@
|
||||
#!/usr/bin/env python
|
||||
"""
|
||||
This script uses Gradle to execute the TexttestFixture.
|
||||
It is designed to be used by TextTest and specified in the file 'texttests/config.gr' in this repo.
|
||||
It is more convenient for TextTest to use since Gradle needs
|
||||
several arguments in addition to the one the TextTest fixture needs.
|
||||
"""
|
||||
import os
|
||||
import subprocess
|
||||
import sys
|
||||
|
||||
args = " ".join(sys.argv[1:])
|
||||
TEXTTEST_HOME = os.environ.get("TEXTTEST_HOME", os.getcwd())
|
||||
subprocess.run(f"{TEXTTEST_HOME}/Java/gradlew -p {TEXTTEST_HOME}/Java -q text --args {args}", shell=True)
|
||||
1
texttests/.gitignore
vendored
Normal file
1
texttests/.gitignore
vendored
Normal file
@ -0,0 +1 @@
|
||||
venv
|
||||
@ -1,37 +1,50 @@
|
||||
# TextTest regression tests
|
||||
|
||||
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.
|
||||
This folder contains Text-Based Approval tests for the GildedRose Refactoring Kata designed by Emily Bache. 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).
|
||||
|
||||
## Install TextTest
|
||||
|
||||
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:
|
||||
## Configure the language version you want to test
|
||||
|
||||
> pip install texttest
|
||||
|
||||
## 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. (Note some languages like Java need several lines uncommented)
|
||||
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.
|
||||
|
||||
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
|
||||
|
||||
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.
|
||||
Follow the instructions on [texttest.org](https://texttest.org/) to install the command-line tool for your platform. You will first need to install Python and probably create a virtual environment before installing TextTest as a python package via pip.
|
||||
|
||||
# replace this path with wherever you cloned this repo
|
||||
> cd /home/ec2-user/workspace/GildedRose-Refactoring-Kata
|
||||
> texttest &
|
||||
Open a terminal and change directory to the root folder of the GildedRose-Refactoring-Kata repo. Texttest detects the current working directory and uses that as the variable $TEXTTEST_HOME in the config.gr file. Alternatively set the environment TEXTTEST_HOME to the full path to this location.
|
||||
|
||||
Execute this command in a terminal:
|
||||
|
||||
texttest -con
|
||||
|
||||
You should see output like this if the test passes:
|
||||
|
||||
Using local queues for Application Gilded Rose Refactoring Kata
|
||||
Q: Submitting Gilded Rose Refactoring Kata test-case ThirtyDays to default local queue
|
||||
S: Gilded Rose Refactoring Kata test-case ThirtyDays succeeded on Emilys-MBP
|
||||
|
||||
If the test fails it might look like this:
|
||||
|
||||
Using local queues for Application Gilded Rose Refactoring Kata
|
||||
Q: Submitting Gilded Rose Refactoring Kata test-case ThirtyDays to default local queue
|
||||
S: Gilded Rose Refactoring Kata test-case ThirtyDays FAILED on Emilys-MBP : differences in stdout
|
||||
View details(v), Approve(a) or continue(any other key)?
|
||||
|
||||
|
||||
If you press 'v' it will try to open the diff tool you specified in 'config.gr' to show you the difference in output. If you press 'a' it will update the approved file - you will not want to do this if you are refactoring. Any other key will return you to the terminal prompt.
|
||||
|
||||
## TextTest user interface
|
||||
|
||||
TextTest has a graphical user interface you can use to manage your test cases. With only one test case it may not be worth it, but if you want to add other tests and/or examine test failures more closely it can be helpful. Start texttest without the 'con' argument:
|
||||
|
||||
texttest &
|
||||
|
||||
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.
|
||||
|
||||
If the texttest GUI doesn't work, or you prefer to use the command line, use this instead:
|
||||
|
||||
> texttest -con
|
||||
|
||||
That will run all the test cases it finds and report the results.
|
||||
|
||||
## Running without TextTest
|
||||
|
||||
This should be perfectly possible, but is probably less convenient than using TextTest.
|
||||
@ -40,7 +53,7 @@ Write a script that will execute the system under test (see "config.gr" for deta
|
||||
|
||||
## 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 Master" 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 approved version 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)
|
||||
@ -49,7 +62,7 @@ Each test case has it's own subdirectory. The name of the directory is the name
|
||||
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.
|
||||
- __environment.gr__ - this file lists environment variables that will be set before TextTest runs the SUT. This is especially important for Java applications, that need to 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.
|
||||
|
||||
Binary file not shown.
@ -11,7 +11,11 @@ diff_program:meld
|
||||
# Settings for the cpp version
|
||||
#executable:${TEXTTEST_HOME}/cpp/cmake-build-debug/test/cpp_texttest/GildedRoseTextTests
|
||||
|
||||
# Settings for the Java version
|
||||
# Settings for the Java version using Gradle wrapped in a python script
|
||||
#executable:${TEXTTEST_HOME}/Java/texttest_rig.py
|
||||
#interpreter:python
|
||||
|
||||
# Settings for the Java version using the classpath
|
||||
#executable:com.gildedrose.TexttestFixture
|
||||
#interpreter:java
|
||||
# note you'll also need to update the file environment.gr with your classpath if you keep your classfiles somewhere unusual
|
||||
|
||||
Loading…
Reference in New Issue
Block a user