HearthSim / Hearthstone-Deck-Tracker

A deck tracker and deck manager for Hearthstone on Windows
https://hsreplay.net/downloads/
4.61k stars 1.11k forks source link

SecretTests fail after using build during a Standard format game #3331

Open mgiuffrida opened 7 years ago

mgiuffrida commented 7 years ago

These tests assume the Game is in Wild format, or more accurately, is not in Standard format.

  1. Build solution
  2. Run SingleSecret tests -- they pass.
  3. Open Hearthstone and start a Standard format game.
  4. Run solution, wait for HDT to load and show the overlay, then stop/quit.
  5. Run SingleSecret tests -- they fail.

Example failure:

Test Name:  SingleSecret_MinionPlayed
Test FullName:  HDTTests.Hearthstone.SecretTests.SingleSecret_MinionPlayed
Test Source:    D:\dev\projects\HearthSim\Hearthstone-Deck-Tracker\HDTTests\Hearthstone\SecretTests.cs : line 180
Test Outcome:   Failed
Test Duration:  0:00:00.4077775

Result StackTrace:  
at System.Collections.Generic.Dictionary`2.get_Item(TKey key)
   at HDTTests.Hearthstone.SecretTests.VerifySecrets(Int32 secretIndex, List`1 allSecrets, String[] triggered) in D:\dev\projects\HearthSim\Hearthstone-Deck-Tracker\HDTTests\Hearthstone\SecretTests.cs:line 239
   at HDTTests.Hearthstone.SecretTests.SingleSecret_MinionPlayed() in D:\dev\projects\HearthSim\Hearthstone-Deck-Tracker\HDTTests\Hearthstone\SecretTests.cs:line 182
Result Message: 
Test method HDTTests.Hearthstone.SecretTests.SingleSecret_MinionPlayed threw exception: 
System.Collections.Generic.KeyNotFoundException: The given key was not present in the dictionary.

Root cause: Secret tests try to verify that each Secret is possible, except for the ones that would have been triggered, e.g.:

VerifySecrets(0, HunterSecrets.All, HunterSecrets.Snipe);

This will fail if some state is left around that makes the test think the game is in Standard format, because while HunterSecrets.All includes secrets like Bear Trap, SecretHelper.GetSecretIds will only return valid secrets in that game mode.

mgiuffrida commented 7 years ago

Is there a way to force Wild format during tests? Or to just not use any state that the build may have lying around?

The alternative is to ensure Standard only secrets are being checked, e.g. replace HunterSecrets.All in the test with HunterSecrets.GetCards(true), but then we're only testing Standard.

azeier commented 7 years ago

It doesn't matter when you build the solution, this problem only occurs if you are in a (standard) match while running the test.

There is no need to fix this on the test level, the underlying logic needs to be separated better.

mgiuffrida commented 7 years ago

To clarify, the test failure continues after closing the Hearthstone client (and the deck tracker of course).

I actually didn't run the tests until after the first time I launched and exited my build, so I never saw these tests pass at first. I assumed they were just broken, and it wasn't until I started debugging it that I found the root of the problem.

azeier commented 7 years ago

Weird, the tests run fine for me as soon as I exit the match.