vendredi 3 mars 2017

How can I get all methods which are called by a testMethod? (Java, TestNG, IAnnotationTransformer)

I'm currently using IAnnotationTransformer to exclude all tests listed in an XML which contain a particular string in their name, for example:

@Override
@SuppressWarnings("rawtypes")
public void transform(ITestAnnotation annotation, Class testClass, Constructor testConstructor, Method testMethod) {
    if(testMethod.getName().contains("StringGoesHere")){
            annotation.setEnabled(false);
        }

This works perfectly well, however due to the naming convention of my tests, and the vast amount of tests which I need to exclude, the ideal solution would be to find a way to exclude the test if it calls upon a particular method. For example, I want to exclude all tests which call upon the method .clickUserSettings() shown below:

@Test
public void editUserDetailsOnStackOverflow() {
    final StackOverflow so = stackOverflow.loginAsMe()
            .clickUserSettings()
            .changeUserEmail()
            .clickSave()
            .assertChangeSuccessful();
}

Does anyone know how I might be able to achieve this? I feel like I've explored all other avenues (classes, packages, testMethods, groups, xml, etc) And the reason it has to be done in this way is because I currently have 40,000 tests (15,000 of which will likely be excluded depending on the browserMode variable set by the tester) This is the general idea I was hoping to achieve:

@Override
@SuppressWarnings("rawtypes")
public void transform(ITestAnnotation annotation, Class testClass, Constructor testConstructor, Method testMethod) {
    if(testMethod.getAllCalledMethods.contains(".clickUserSettings()")){
            annotation.setEnabled(false);
        }

If this can be done it will solve my issue,

Cheers

Aucun commentaire:

Enregistrer un commentaire