-
Notifications
You must be signed in to change notification settings - Fork 7
Style guidelines
Joshua Gleitze edited this page Mar 22, 2015
·
5 revisions
To provide good readability of your tests, please stick to the following style guidelines:
The repository contains xml configuration files for the Eclipse Formatter tool. Please import it and apply it before commiting!
Create exactly one method to test one thing.
- Testing a
search
command's parsing syntax:- create one
testCorrectSearch()
method, nottestCorrectSearch1()
,testCorrectSearc2()
, etc. - create another method for invalid searches, like
testInvalidSearch()
. Do not put invalid searches intotestCorrectSearch()
.
- create one
Tests with more than some hundred lines are getting very hard to read. Use JUnit Test Suites to split them up into multiple files.
- Only put the test suite running all tests in the top level package of your test
- Create a subpackage
subtests
for the different test classes.
- Sheet 6 Task C has:
-
BookDatabaseTest
in the packagesheet6.c_bookDatabase
. It runs all the subtests. -
BookDatabaseSubtest
in the packagesheet6.c_bookDatabase.subtests
contains some common fields and methods for subtests. -
BasicCommandsTest
in the packagesheet6.c_bookDatabase.subtests
tests whether the program supports the basic commands -
InputFileParsingTest
in the packagesheet6.c_bookDatabase.subtests
tests wheter the correctly reads in input files - etc.
-
If you want to test a interactive console, make your test extend InteractiveConsoleTest and use its methods.
- State the command you will be running and the result you expect before running the test. Use the appropriate fields of
InteractiveConsoleTest
(e.g.command
,expectedResults
, etc.). - Use the array notation for multiple commands or multiple expected results. If you want to use matchers, use
getMatchers(Matcher...)
- Use the array notation for input files. Use
getFile(String[])
of the Input class to pass the file to the program.
-
command = "search title=Musterbuch"; expectedResult = "creator=galileocomputing,title=java_ist_auch_eine_insel,year=unknown,false"; oneLineTest(command, expectedResult, args);
-
commands = new String[] { "command1", "command2", "etc." }; expectedResults = new String[] { "result1", "result2", "etc." }; multiLineTest(commands, expectedResults, args);
file = new String[] { "creator=galileocomputing,title=java_ist_auch_eine_insel", "title=grundkursprogrammieren_in_java,year=2007", "creator=ralf_reussner,year=2006" }; commands = new String[] { "search creator=ralf_reussner", "search year=2006", "search AND(creator=ralf_reussner,year=2006)", "search OR(creator=ralf_reussner,year=2006)", "search isbn=12345", "quit" }; // @formatter:off expectedResultMatchers = getMatchers( is("creator=galileocomputing,title=java_ist_auch_eine_insel,year=unknown,false"), is("creator=unknown,title=grundkursprogrammieren_in_java,year=2007,false"), is("creator=ralf_reussner,title=unknown,year=2006,true"),is("creator=galileocomputing,title=java_ist_auch_eine_insel,year=unknown,false"), is("creator=unknown,title=grundkursprogrammieren_in_java,year=2007,true"), is("creator=ralf_reussner,title=unknown,year=2006,true"), is("creator=galileocomputing,title=java_ist_auch_eine_insel,year=unknown,false"), is("creator=unknown,title=grundkursprogrammieren_in_java,year=2007,false"), is("creator=ralf_reussner,title=unknown,year=2006,true"), is("creator=galileocomputing,title=java_ist_auch_eine_insel,year=unknown,false"), is("creator=unknown,title=grundkursprogrammieren_in_java,year=2007,true"), is("creator=ralf_reussner,title=unknown,year=2006,true"), startsWith("Error,") ); // @formatter:on multiLineTest(commands, expectedResultMatchers, "0.5", Input.getFile(file));