Stendhal Quest Testing

From Arianne
Revision as of 21:02, 26 November 2010 by imported>Kymara (Run the test and make corrections)
Jump to navigation Jump to search



Stendhal Quests

Generate a chat log

We need chat logs of players doing each Stendhal Quest so that we can create tests for them. So, it's easy to help us because all you need to do, is do the quest and then save the chat log for us. There are some ways you can help us make the best possible test:

  • don't say yes to everything immediately. try saying no and then come back and say yes
  • try to fool the npc. if he asked you for an item, say you had it when you didn't really! or if you were supposed to kill something, say yes you did, before you really did.
  • if it's repeatable, try to come back and do it too early, and then again later
  • if it's not repeatable, try to come back and ask for a quest again anyway!

Some quests have already got a test written for them because chat logs have been provided. Please take a look at the report from hudson - quests which are all or mostly green are done, and quests which are all or mostly red need a chatlog provided.

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.

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 playerNames.

Open src/games/stendhal/tools.test/ChatTestCreator.java in the editor in Eclipse then go to the green arrow button for running an application.

 Run Configurations ... 
 Arguments tab
 Program arguments: gamechat.log
 Click Run

If all is well you should get some text output into your Console starting with

package games.stendhal.server.maps.quests;

import static org.junit.Assert.assertEquals;
import games.stendhal.server.core.engine.SingletonRepository;

and it will be plain with no coloured highlighting.

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!

<source lang = "java"> public class TODO_Test {

private Player player = null; private SpeakerNPC npc = null; private Engine en = null;

@BeforeClass public static void setUpBeforeClass() throws Exception { QuestHelper.setUpBeforeClass(); }

@Before public void setUp() { final StendhalRPZone zone = new StendhalRPZone("admin_test"); new TODO_NPC().configureZone(zone, null);


AbstractQuest quest = new TODO_Quest(); quest.addToWorld();

player = PlayerTestHelper.createPlayer("bob"); }

       @Test

public void testQuest() {

npc = SingletonRepository.getNPCList().get(TODO_Name); </source>

TODO_Test

This is the class name of your test file. Which should be the class name of the quest file you are testing, plus 'Test'. Ours is RainbowBeansTest.

TODO_NPC()

Locate the maps file for the NPC in your quest (hint: search the src/games/stendhal/server/maps folder for their name) then use the class name of their maps file

We searched Pdiddi and found he is defined in src/games/stendhal/server/maps/semos/pad/DealerNPC.java - so we replaces TODO_NPC() with DealerNPC() and added the import needed.

If you have more than one NPC active in this quest you need to add them! Just copy and paste the line and repeat for each NPC.

TODO_Quest

This is the class name of the quest file you are testing. For us, that's RainbowBeans.

TODO_Name

Fill in here, the name of the first NPC you spoke to for the quest. Put it in quotes : SingletonRepository.getNPCList().get("Pdiddi");

Now the errors should be gone:

<source lang = "java"> public class RainbowBeansTest {

private Player player = null; private SpeakerNPC npc = null; private Engine en = null;

@BeforeClass public static void setUpBeforeClass() throws Exception { QuestHelper.setUpBeforeClass(); }

@Before public void setUp() { final StendhalRPZone zone = new StendhalRPZone("admin_test"); new DealerNPC().configureZone(zone, null);


AbstractQuest quest = new RainbowBeans(); quest.addToWorld();

player = PlayerTestHelper.createPlayer("bob"); }

       @Test

public void testQuest() {

npc = SingletonRepository.getNPCList().get("Pdiddi"); </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

TODO: I think this needs more explanation

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 #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 we try running the test again. The next error is another unexpected response:

 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!]>

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

java games.stendhal.tools.test.ChatTestCreator chatlog.txt [chatlogtest.java]
Exception in thread "main" java.lang.ArrayIndexOutOfBoundsException: 0
at games.stendhal.tools.test.ChatTestCreator.main(ChatTestCreator.java:75)
  • You didn't put gamechat.log into the Program arguments.
Exception in thread "main" java.io.FileNotFoundException: gamechat.log (No such file or directory) 
  • You didn't copy gamechat.log into the project folder for your eclipse workspace.