Stuffer
Stuffer

Reputation: 11

Using reflection or other method to analyse tests

I am not sure if is it possible (Google is saying that not really). I want to create test that will analyse other tests for looking some specific elements like annotation, specific class or other and if something is not good then will fail. How should I analyse tests for looking unwanted elements? Lets say I have unit tests but some programmer used spring context to create context what is weird situation, but I want to catch it. Sorry for my english, I am not native.

@Edit hard to provide specific example but I will try.

Lets say I want to achive something like that:

@Test
void checkIfUnitTestsAreCorrect() {
    // how can I check if tests with @UnitTest build SpringContext?

}

@Test
@UnitTest
void unitTest() {
  // SpringContext is building here so it is wrong
}

Upvotes: 0

Views: 85

Answers (1)

Markus Blank
Markus Blank

Reputation: 11

To accomplish this you would need to get the method body by runtime which is not possible via the reflection API.

Upvotes: 1

Related Questions