question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Tests can only make assertions at one point in the game

See original GitHub issue

Tests are able to make assertions about the state of the game after the execute() command is run, but execute() can only be ran once per test. This prevents tests such as this modification to FinalPunishmentTest.java to assert that playerB’s life total is reduced to 18 and then 16 sequentially. While this particular example might not be too valuable, there are many potential tests where it’s useful to assert the state of the game at different points in the game, rather than only at one point after running execute().

Replication

  • Run a test case in FinalPunishmentTest.java:
mvn install test -DfailIfNoTests=false -Dtest=FinalPunishmentTest#lifelossBecauseOfCombat
  • Note the test passes
  • Update FinalPunishmentTest.java by adding the lines added in this branch
  • Run the same test case again and note it no longer passes:
[INFO] -------------------------------------------------------
[INFO]  T E S T S
[INFO] -------------------------------------------------------
[INFO] Running org.mage.test.cards.single.scg.FinalPunishmentTest
[ERROR] Tests run: 1, Failures: 1, Errors: 0, Skipped: 0, Time elapsed: 35.23 s <<< FAILURE! - in org.mage.test.cards.single.scg.FinalPunishmentTest
[ERROR] org.mage.test.cards.single.scg.FinalPunishmentTest.lifelossBecauseOfCombat  Time elapsed: 35.005 s  <<< FAILURE!
java.lang.AssertionError: Life amounts are not equal for player PlayerB expected:<16> but was:<18>
	at org.mage.test.cards.single.scg.FinalPunishmentTest.lifelossBecauseOfCombat(FinalPunishmentTest.java:50)

[INFO]
[INFO] Results:
[INFO]
[ERROR] Failures:
[ERROR]   FinalPunishmentTest.lifelossBecauseOfCombat:50->CardTestPlayerAPIImpl.assertLife:798 Life amounts are not equal for player PlayerB expected:<16> but was:<18>
[INFO]
[ERROR] Tests run: 1, Failures: 1, Errors: 0, Skipped: 0
[INFO]
[INFO] ------------------------------------------------------------------------
[INFO] Reactor Summary:
[INFO]
[INFO] Mage Root 1.4.50 ................................... SUCCESS [  0.594 s]
[INFO] Mage Framework 1.4.50 .............................. SUCCESS [  2.515 s]
[INFO] Mage Common Classes 1.4.50 ......................... SUCCESS [  0.135 s]
[INFO] Mage Sets 1.4.50 ................................... SUCCESS [  3.536 s]
[INFO] Mage Server Plugins 1.4.50 ......................... SUCCESS [  0.009 s]
[INFO] Mage Player AI 1.4.50 .............................. SUCCESS [  0.051 s]
[INFO] Mage Deck Constructed 1.4.50 ....................... SUCCESS [  0.028 s]
[INFO] Mage Deck Limited 1.4.50 ........................... SUCCESS [  0.028 s]
[INFO] Mage Game Commander Two Player 1.4.50 .............. SUCCESS [  0.023 s]
[INFO] Mage Game Brawl Two Player 1.4.50 .................. SUCCESS [  0.039 s]
[INFO] Mage Game Commander Free For All 1.4.50 ............ SUCCESS [  0.034 s]
[INFO] Mage Game Brawl Free For All 1.4.50 ................ SUCCESS [  0.022 s]
[INFO] Mage Game Free For All 1.4.50 ...................... SUCCESS [  0.032 s]
[INFO] Mage Game Two Player 1.4.50 ........................ SUCCESS [  0.021 s]
[INFO] Mage Player Human 1.4.50 ........................... SUCCESS [  0.036 s]
[INFO] Mage Player AI Minimax 1.4.50 ...................... SUCCESS [  0.040 s]
[INFO] Mage Player AI.MA 1.4.50 ........................... SUCCESS [  0.045 s]
[INFO] Mage Player AI MCTS 1.4.50 ......................... SUCCESS [  0.024 s]
[INFO] Mage Tournament Booster Draft 1.4.50 ............... SUCCESS [  0.041 s]
[INFO] Mage Tournament Sealed 1.4.50 ...................... SUCCESS [  0.034 s]
[INFO] Mage Tournament Constructed 1.4.50 ................. SUCCESS [  0.023 s]
[INFO] Mage Player AI.DraftBot 1.4.50 ..................... SUCCESS [  0.037 s]
[INFO] Mage Game Tiny Leaders Two Player 1.4.50 ........... SUCCESS [  0.038 s]
[INFO] Mage Game Canadian Highlander Two Player 1.4.50 .... SUCCESS [  0.017 s]
[INFO] Mage Game Penny Dreadful Commander Free For All 1.4.50 SUCCESS [  0.036 s]
[INFO] Mage Game Freeform Commander Free For All 1.4.50 ... SUCCESS [  0.022 s]
[INFO] Mage Game Freeform Unlimited Commander 1.4.50 ...... SUCCESS [  0.042 s]
[INFO] Mage Game Freeform Commander Two Player 1.4.50 ..... SUCCESS [  0.036 s]
[INFO] Mage Game Oathbreaker Free For All 1.4.50 .......... SUCCESS [  0.021 s]
[INFO] Mage Game Oathbreaker Two Player 1.4.50 ............ SUCCESS [  0.104 s]
[INFO] Mage Game Momir Basic Two Player 1.4.50 ............ SUCCESS [  0.031 s]
[INFO] Mage Game Momir Basic Free for All 1.4.50 .......... SUCCESS [  0.018 s]
[INFO] Mage Server 1.4.50 ................................. SUCCESS [  0.592 s]
[INFO] Mage Plugins 1.4.50 ................................ SUCCESS [  0.009 s]
[INFO] Mage Counter Plugin 0.1 ............................ SUCCESS [  0.044 s]
[INFO] Mage Client 1.4.50 ................................. SUCCESS [  1.186 s]
[INFO] Mage Server Console 1.4.50 ......................... SUCCESS [  0.047 s]
[INFO] Mage Tests 1.4.50 .................................. FAILURE [ 37.191 s]
[INFO] Mage Verify 1.4.50 ................................. SKIPPED
[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time:  47.033 s
[INFO] Finished at: 2022-06-23T19:35:20-07:00
[INFO] ------------------------------------------------------------------------
[ERROR] Failed to execute goal org.apache.maven.plugins:maven-surefire-plugin:3.0.0-M5:test (default-test) on project mage-tests: There are test failures.
[ERROR]
[ERROR] Please refer to /Users/DeepCrimson/code/mage/Mage.Tests/target/surefire-reports for the individual test results.
[ERROR] Please refer to dump files (if any exist) [date].dump, [date]-jvmRun[N].dump and [date].dumpstream.
[ERROR] -> [Help 1]
[ERROR]
[ERROR] To see the full stack trace of the errors, re-run Maven with the -e switch.
[ERROR] Re-run Maven using the -X switch to enable full debug logging.
[ERROR]
[ERROR] For more information about the errors and possible solutions, please read the following articles:
[ERROR] [Help 1] http://cwiki.apache.org/confluence/display/MAVEN/MojoFailureException
[ERROR]
[ERROR] After correcting the problems, you can resume the build with the command
[ERROR]   mvn <args> -rf :mage-tests

Issue Analytics

  • State:closed
  • Created a year ago
  • Comments:6 (6 by maintainers)

github_iconTop GitHub Comments

1reaction
JayDi85commented, Jun 25, 2022

any examples of tests which call execute twice like this

ConduitOfRuinTest

I’m wondering, what’s the purpose of the show

It prints debug info by System.out.println. Example with showAvailableAbilities – it show all playable abilities for the player (player allowed to play it and it has a mana for it). Very useful for fast debugging in the console.

shot_220625_072158

0reactions
DeepCrimsoncommented, Jun 25, 2022

OK got it, thanks a lot for this info!

Read more comments on GitHub >

github_iconTop Results From Across the Web

Stop requiring only one assertion per unit test
A test must have only one assertion. That idea is rarely helpful. Let's examine a realistic code example and subsequently try to understand ......
Read more >
Is it OK to have multiple asserts in a single unit test?
The key is that you have only one action, and then you inspect the results of that action using asserts. But it is...
Read more >
Writing Good Assertions - Manning Publications
Writing loose assertions is acceptable when you want tests not to be tied to factors you can't control, like true randomness. Assume that...
Read more >
Test framework: add commands for real time checks/assertions ...
Current test framework can do checks (assertions) only on game's end. That's a big limit ... Tests can only make assertions at one...
Read more >
PHPUnit passing a test with no assertions within config
I know I could add something like assertTrue(true) however is it possible to add something to the config to make these tests pass...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found