1
1

test_file_template 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124
  1. !! ------------------------------------------------------------------------------------
  2. !! Create a test_<location> for every location you want to test. If the location is too
  3. !! long, there are a lot of tests, break it up into several test_<location>_<description>
  4. !! files. The <description> should be something meaningful, not just 1, 2 or 3.
  5. !! It should be something like test_NPCChat_HatesPlayer, test_NPCChat_SecondQuestChat or
  6. !! something similar to give an idea to people of what is in the file.
  7. !! IMPORTANT:
  8. !! 1. Do not remove the @.... tags.
  9. !! 2. Add a value to all the CAPITALISED variables
  10. !! a. $FUNCTIONNAME can take an empty string in some cases.
  11. !! b. $ARGUMENTS can also be empty if no arguments are passed in the call
  12. !! 4. ACTUAL and EXPECTED can be String or Number depending on what you test.
  13. !! Both are Strings ($) by default because that is safer. $ACTUAL = 2 will work,
  14. !! ACTUAL = 'something' will throw an error.
  15. !! 3. Set up the necessary variables that the tested code will check.
  16. !! 4. The 'testframework', 'testsetup' sets up a lot of things dates, PC attributes, etc.
  17. !! 5. Do not forget to clean up the variables you set: put that code after
  18. !! the 'testframework', 'cleanUpDefault' call
  19. !! 6. Do not be afraid to ask, I am happy to help.
  20. !! Either on the discord or on https://git.tfgames.site/netuttki/qsp_unit_test_proof_of_concept/issues
  21. !! ------------------------------------------------------------------------------------
  22. !! $LOCATIONNAME = the tested location with the test_ prefix.
  23. !! E.g.: test_korrPar, test_internet_mobile, test_prostitution_functions, etc.
  24. !! ------------------------------------------------------------------------------------
  25. !! @locationsetup
  26. _ISTEST = 1
  27. $LOCATIONNAME = ''
  28. !! ------------------------------------------------------------------------------------
  29. !! Run the tests - add the calls to the tests for the location that have to be run.
  30. !! ------------------------------------------------------------------------------------
  31. !! List the tests defined below, i.e. the $ARGS[0] value. The @run tag tells the framework
  32. !! that the test has to be executed.
  33. !! @run test_1 <- this test will run. 'test_1', "test_1" and test_1 are all valid
  34. !! test_2 <- this test will not run
  35. !! ------------------------------------------------------------------------------------
  36. !! The actual test. For each ($)ARGS[0] you want to test write a separate one, ideally
  37. !! testing only one thing at a time - the value of one variable.
  38. !! Never test more than one ($)ARGS[0] values in one test.
  39. !! Even if 'location, 'event2' follow 'location', 'event2' immediately in the game do not do this:
  40. !! gs 'location', 'event1'
  41. !! gs 'location', 'event2
  42. !!
  43. !! If the result of 'event2' turns out to be incorrect you will not know whether the problem is in
  44. !! 'event1' or in 'event2'.
  45. !! ------------------------------------------------------------------------------------
  46. !! @tests
  47. !! Test Function Template
  48. !! Comment if needed about the test
  49. if $ARGS[0] = '':
  50. !! $TESTNAME: 'A relatively short but descriptive name for the test explaining what is tested.'
  51. !! For example "If mainQuest['stage'] = 2 the Archenemy should be Kevin"
  52. $TESTNAME = ''
  53. !! $FUNCTIONNAME: The value of $ARGS[0]
  54. !! For example 'setArchenemy'
  55. $FUNCTIONNAME = ''
  56. !! Checks if the $LOCATIONNAME, $FUNCTIONNAME pair is valid.
  57. if _ISVALIDCALL['<<$LOCATIONNAME>>,<<$FUNCTIONNAME>>'] ! 0:
  58. !! Setup
  59. gs 'testframework', 'testsetup'
  60. !! Under setup the test has to assign the values to every variable that is used by the tested code.
  61. !! For example:
  62. !! mainQuest['stage'] = 2
  63. !! $EXPECTED = or EXPECTED = is the value that the test is expecting after the test runs.
  64. !! For example:
  65. !! $EXPECTED = 'Kevin'
  66. !! $EXPECTED_MESSAGE = "$nameOfArchenemy = <<$EXPECTED>>"
  67. $EXPECTED = ''
  68. $EXPECTED_MESSAGE = ""
  69. !! Add the argument values if any as a string.
  70. !! For example $ARGUMENTS = "'archenemy', 1" - Right now $ARGUMENTS is used only to display the arguments
  71. !! in the test result reports.
  72. $ARGUMENTS = ''
  73. !! Add the same arguments after the $FUNCTIONNAME
  74. gs $LOCATIONNAME, $FUNCTIONNAME
  75. *clr & cla
  76. !! The variable in the tested code that we are checking here.
  77. !! For example $nameofArchenemy.
  78. !! $ACTUAL = $nameOfArchenemy
  79. !! $ACTUAL_MESSAGE = "$nameOfArchenemy = '<<$ACTUAL>>'"
  80. $ACTUAL
  81. $ACTUAL_MESSAGE = ""
  82. !! Assertion of the outcome.
  83. !! Compare the EXPECTED and ACTUAL values - adding some functions later for more complicated assertions,
  84. !! like comparing arrays and whatever comes up.
  85. TESTRESULT = $EXPECTED = $ACTUAL
  86. else:
  87. !! If the $LOCATIONNAME - $FUNCTIONNAME pair is an invalid call then the $ACTUAL_MESSAGE is set to convey this message.
  88. $ACTUAL_MESSAGE = '<<$LOCATIONNAME>> <<$FUNCTIONNAME>> does not exist.'
  89. end
  90. !! ------------------------------------------------------------------------------------
  91. !! Add testresult to the reports.
  92. !! ------------------------------------------------------------------------------------
  93. gs 'testframework', 'addTestResult'
  94. !! ------------------------------------------------------------------------------------
  95. !! Clean up the variables for the next test.
  96. !! ------------------------------------------------------------------------------------
  97. gs 'testframework', 'testCleanUpDefault'
  98. !! add cleanup for any variables that you used for the test.
  99. !! For example:
  100. !! killvar 'mainQuest'
  101. !! killvar 'nameOfArchenemy'
  102. end
  103. killvar 'LOCATIONNAME'
  104. killvar '_ISTEST'