Stendhal Quest Testing: Difference between revisions

Jump to navigation Jump to search
Content deleted Content added
imported>Kymara
No edit summary
imported>Kymara
No edit summary
Line 16: Line 16:
== Run ChatTestCreator ==
== Run ChatTestCreator ==
Once you have the chatlog you can use games.stendhal.tools.test.ChatTestCreator to make a test. We assume you are using eclipse. First, copy the chat log into the project folder of your Stendhal project. For this tutorial we are using [[File:Test Gamechat.log]] - save it and rename it to gamechat.log like your own chatlogs would be, if you want to follow the tutorial exactly.
Once you have the chatlog you can use games.stendhal.tools.test.ChatTestCreator to make a test. We assume you are using eclipse. First, copy the chat log into the project folder of your Stendhal project. For this tutorial we are using [[File:Test Gamechat.log]] - save it and rename it to gamechat.log like your own chatlogs would be, if you want to follow the tutorial exactly.

Next make sure the character who made the chatlog is added to the list of testers.

Open src/games/stendhal/tools.test/LineAnalyser.java and add your name to <code>playerNames</code>.


Open src/games/stendhal/tools.test/ChatTestCreator.java in the editor in Eclipse then go to the green arrow button for running an application.
Open src/games/stendhal/tools.test/ChatTestCreator.java in the editor in Eclipse then go to the green arrow button for running an application.
Line 35: Line 39:
Cope and paste all that text into a new file which you should save in tests/games/stendhal/server/maps/quests/. Call it the same name as the class file for your Quest, with 'Test' at the end. We are testing RainbowBeans.java, so we name the file, RainbowBeansTest.java.
Cope and paste all that text into a new file which you should save in tests/games/stendhal/server/maps/quests/. Call it the same name as the class file for your Quest, with 'Test' at the end. We are testing RainbowBeans.java, so we name the file, RainbowBeansTest.java.


== Get the test to compile==
Now there will be some red underlined errors in the file, for each part which is TODO. Don't worry about that!
Now there will be some red underlined errors in the file, for each part which is TODO. Don't worry about that!


Line 114: Line 119:
</source>
</source>


Finally I like to edit the text so that each conversation block is together. After each 'bye' from the npc, make a new line so that we're nicely split out.


== Run the test and make corrections ==

Now right click the file:
Run As ...
Junit test

It will fail, don't worry!

The trace for our example says

expected:<...undry knowin' wot I []deal in.> but was:<...undry knowin' wot I [#]deal in.>

The problem is that the chatlog didn't preserve any of those special {{chathighlight|hash}}. So it looks like a mistake. Just modify the test by adding in the hash as needed:
assertEquals("SHHH! Don't want all n' sundry knowin' wot I #deal in.", getReply(npc));

Once all those are fixed the next error is another unexpected response:
<pre>
org.junit.ComparisonFailure: expected:<[Nosy, aint yer? I deal in rainbow beans. You take some, and who knows where the trip will take yer. It'll cost you 2000 money. You want to buy some?]> but was:<[It's not stuff you're ready for, pal. Now get out of 'ere! An don't you come back till you've got more hairs on that chest!]>
</pre>
The player who tested it had enough level to buy the rainbow beans but this player is just a zero level player created for the test.

So we need to increase the level before we say hi, and we might as well check it's enough using an Assert (add the imports if needed)
<source lang = "java">
// player was too low level last time. make them at least level 30
player.addXP(248800);
assertThat(player.getLevel(), greaterThanOrEqualTo(30));
</source>

If you're having trouble with imports just add, with the imports,
<source lang = "java">
import static org.hamcrest.Matchers.*;
import static org.junit.Assert.*;
</source>

The next error is that we don't have the money to pay for the beans. So, after saying "yes" we want the beans, we need to give the money.
<source lang = "java">
PlayerTestHelper.equipWithMoney(player, 2000);
</source>
== Trouble shooting ==
== Trouble shooting ==
java games.stendhal.tools.test.ChatTestCreator chatlog.txt [chatlogtest.java]
java games.stendhal.tools.test.ChatTestCreator chatlog.txt [chatlogtest.java]