D
D
danbulochkin2020-04-29 13:50:08
Java
danbulochkin, 2020-04-29 13:50:08

How to annotate all classes with @BeforeClass?

I have test classes, tests are run using gradle.
It is necessary to annotate all classes with @BeforeClass and @AfterClass that will perform their specific actions.
I tried to create an interface with these annotations and inherit in all the necessary classes
. The problem is that the @BeforeClass and @AfterClass annotations are executed before the launch of each class called by the gradle.
Add. question: do not tell me how to run only one class with a gradle, not all at once.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
avborg, 2020-04-29
@avborg

In such a formulation of the question

It is necessary to annotate all classes with @BeforeClass and @AfterClass that will perform their specific actions.

You did everything right - through inheritance.
The problem is that the @BeforeClass and @AfterClass annotations are executed before each gradle class is called.

This is not a problem, this is the expected functionality of these annotations.
If you want some piece of code to be executed once before/after several test classes, you can use @SuiteClasses({Test1.class, Test2.class}) ( see stackoverflow example )

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question