Skip to content

TestNG @BeforeClass Mocks not torn down after class finishes #107

@thelateperseus

Description

@thelateperseus

If I write test that sets up a Mock in a method annotated with @BeforeMethod, that mock is correctly torn down after the method completes. However, if I change the annotation to @BeforeClass, that mock is not correctly torn down. I think that this is because the TestNGRunnerDecorator does not implement the ITestListener interface and tear down mocks after the class finishes.

So in summary, the following works as expected:

@BeforeMethod
public void setup() {
    new MockThatExtendsMockUp();
}

But the following does not:

@BeforeClass
public void setup() {
    new MockThatExtendsMockUp();
}

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions