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.

Test framework: add commands for real time checks/assertions

See original GitHub issue

Current test framework can do checks (assertions) only on game’s end. That’s a big limit – devs need to create plenty of tests to reproduce and check each step (e.g. you can test only final result). But with real time checks you can assert errors in the middle of the game (e.g. you can test all progress to final result).

Framework must allow to insert checks like other player commands and generate standard test errors:

  • color (have or not have) – checkColor;
  • card type (have or not have);
  • card subtype (have or not have) – checkSubType;
  • ability (have or not have) – checkAbility;
  • power and toughness – checkPT;
  • permanent count – checkPermanentCount;
  • hand count – checkHandCount;
  • graveyard count;
  • damage
  • exile count;
  • command zone count;
  • counters count;
  • mana pool;
  • player life;

Other:

  • add “resolve” command to wait stack resolving in same step (cast 1, resolve, cast 2);

Code example with real time checks:

    public void test_DaxosGotBoostAndSaveColor() {
        addCard(Zone.HAND, playerA, daxosCard, 1);
        addCard(Zone.BATTLEFIELD, playerA, "Swamp", 4);
        //
        addCard(Zone.HAND, playerA, "Chaoslace", 1); // Target spell or permanent becomes red.
        addCard(Zone.BATTLEFIELD, playerA, "Mountain", 1);
        //
        addCard(Zone.HAND, playerA, "Archetype of Courage", 1); // Enchantment to trigger Daxos
        addCard(Zone.BATTLEFIELD, playerA, "Plains", 4);

        // dax cast
        castSpell(1, PhaseStep.PRECOMBAT_MAIN, playerA, daxosCard);
        checkPermanentCount("dax exist", 1, PhaseStep.POSTCOMBAT_MAIN, playerA, daxosCard, 1);
        checkColor("dax without color", 1, PhaseStep.POSTCOMBAT_MAIN, playerA, daxosCard, "R", false);
        // give dax new color
        castSpell(3, PhaseStep.PRECOMBAT_MAIN, playerA, "Chaoslace", daxosCard);
        checkPT("dax not boost", 3, PhaseStep.BEGIN_COMBAT, playerA, daxosCard, 0, 0);
        checkColor("dax is red", 3, PhaseStep.BEGIN_COMBAT, playerA, daxosCard, "R", true);
        // color is saved on boost
        castSpell(5, PhaseStep.PRECOMBAT_MAIN, playerA, "Archetype of Courage"); // make dax to creature
        checkPT("dax boost", 5, PhaseStep.BEGIN_COMBAT, playerA, daxosCard, 5, 5);
        checkAbility("dax fly", 5, PhaseStep.BEGIN_COMBAT, playerA, daxosCard, FlyingAbility.class, true);
        checkColor("dax is red", 5, PhaseStep.BEGIN_COMBAT, playerA, daxosCard, "R", true);

        setStopAt(5, PhaseStep.END_TURN);
        execute();
    }

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Comments:9 (8 by maintainers)

github_iconTop GitHub Comments

1reaction
Alex-Vasilecommented, Jun 28, 2022

Is someone working on fixing those old tests? If not I could take that mantle

https://github.com/magefree/mage/blob/e1cf2fd7e077ae9a3e9dd9694e3cede923546631/Mage.Tests/src/test/java/org/mage/test/serverside/base/impl/CardTestPlayerAPIImpl.java#L289

Feel free to enable, and add a PR.

1reaction
Alex-Vasilecommented, Jun 28, 2022

Thanks for the tips and heads up, I’ll check out that test file.

@the-red-lily you must use setStrictChooseMode (test will raise error on miss choice command) and assertAllCommandsUsed (test will raise error on wrong/unused commands – your use case).

Why are these modes not enabled by default?

I am working on enabling assertAllCommandsUsed. The reason it’s not enabled is since many tests have errors that need fixing. (it was added after the tests were written).

The setStrictChooseMode is not needed for all tests since some choices are okay for the AI to autochoose (e.g only one option available).

Read more comments on GitHub >

github_iconTop Results From Across the Web

Assertions In Selenium Using Junit And TestNG Frameworks
Assertions are used to perform various kinds of validations in the test cases, which in turn helps us to decide whether the test...
Read more >
How To Use Assertions In TestNG With Selenium - LambdaTest
In this TestNG tutorial, you will learn how to use different assertions in TestNG and see how they are helpful in Selenium automation...
Read more >
Assert and Verify Methods in Selenium | BrowserStack
Understand the difference between assert and verify in Selenium with command examples to execute types of Assert methods.
Read more >
How To Use TestNG Asserts with Selenium To ... - Tools QA
Since we are now well versed with all the significant concepts in TestNG, it is time to execute some actual tests using selenium...
Read more >
Python's assert: Debug and Test Your Code Like a Pro
In practice, you can use assertions to check preconditions and postconditions in your programs at development time. For example, programmers ...
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