New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Setting up @Tested object in a @BeforeMethod #461

Closed
WatchfulLikeACrane opened this Issue Sep 20, 2017 · 0 comments

Comments

2 participants
@WatchfulLikeACrane

WatchfulLikeACrane commented Sep 20, 2017

Please provide the following information:

  • Version of JMockit that was used:
    JMockit 1.34
    TestNG 6.12
  • Description of the problem:

It seems that the availableDuringSetup parameter of the @Tested annotation constructs the annotated object only once for all unit tests in the class. Hopefully this example will show quickly what I mean:

class TestedClass {
    int addCount = 1;

    public void add() {
        System.out.println(addCount++);;
    }
}

public class Test {

    @Tested(availableDuringSetup = true)
    TestedClass testedClass;

    @org.testng.annotations.BeforeMethod
    public void setup() {
    }

    @org.testng.annotations.Test
    public void test_1() {testedClass.add(); }
    @org.testng.annotations.Test
    public void test_2() {testedClass.add(); }
}

Output for availableDuringSetup = true : 1 2
Output for availableDuringSetup = false: 1 1

Is that intentional? And if so, then is there some other way to force the reconstruction of the @Tested object before each execution of the @BeforeMethod?

@rliesenfeld rliesenfeld self-assigned this Sep 20, 2017

@rliesenfeld rliesenfeld added the bug label Sep 20, 2017

@jmockit jmockit locked and limited conversation to collaborators Oct 11, 2017

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.