dimanche 20 décembre 2020

running single class test that triggers many - surefire report

I'm running a group of tests in parallel, with parallel computer. the problem is when I run my build in jenkins, all my tests classes are also running.

meaning - if I have 2 classes- X.class, Y.class and I'm running them on parallel in class Z.class, when I run my build on Jenkins, he runs all classes (X.class, Y.Class, Z.class)... and that wasn't really my purpose.

to avoid this, I've used - "-Dtest=Z.class", and now Im running only my multithreaded class. everything works great, except for one thing-

surefire creates my reports only for my Z.class. so if Z.class triggered 2 classes, each has 5 tests, instead of reporting 10 tests, he reports only 1 test - my Z.class

this is my code-

@Test
public void runAllTest() throws ClassNotFoundException {
    List<Class<?>> classesList = new ArrayList<Class<?>>();

    final ClassPathScanningCandidateComponentProvider provider = new ClassPathScanningCandidateComponentProvider(false);
    provider.addIncludeFilter(new RegexPatternTypeFilter(Pattern.compile(".*")));
    final Set<BeanDefinition> classes = provider.findCandidateComponents("xxx.Mypackage.tests");

    for (BeanDefinition bean: classes) {
        classesList.add(Class.forName(bean.getBeanClassName()));
    }

    Class<?>[] itemsArray = new Class<?>[classesList.size()];
    itemsArray = classesList.toArray(itemsArray);

    Result result = JUnitCore.runClasses(new ParallelComputer(true, true), itemsArray);

My report-

[main] INFO org.apache.maven.plugin.surefire.SurefirePlugin - Tests run: 1, Failures: 0, Errors: 0, Skipped: 0

how can I run only only one class test that triggers many, and still have a valid report?

thanks

Aucun commentaire:

Enregistrer un commentaire