Sonarqube 与jacoco一起运行时,gwt测试utils单元失败

Sonarqube 与jacoco一起运行时,gwt测试utils单元失败,sonarqube,gwt-test-utils,Sonarqube,Gwt Test Utils,我们正试图从使用GWT测试UTIL编写的一组单元测试生成GWT应用程序的覆盖率报告。该项目是一个多模块maven项目。我们在jenkins上使用sonar插件来生成和整理我们的覆盖范围和违规信息 当构建作业运行所有GWT单元测试作为正常构建的一部分通过时,但是当Sonar插件尝试重新运行测试时,它们都会失败,并出现以下错误: 初始化错误(uk.co.card.gwt.retailpost.client.dialog.productmodify.CurrencyEditDialogTest)经过的

我们正试图从使用GWT测试UTIL编写的一组单元测试生成GWT应用程序的覆盖率报告。该项目是一个多模块maven项目。我们在jenkins上使用sonar插件来生成和整理我们的覆盖范围和违规信息

当构建作业运行所有GWT单元测试作为正常构建的一部分通过时,但是当Sonar插件尝试重新运行测试时,它们都会失败,并出现以下错误:


初始化错误(uk.co.card.gwt.retailpost.client.dialog.productmodify.CurrencyEditDialogTest)经过的时间:0秒正如我在评论中提到的,对于带有maven surefire插件的jacoco,库以不同的顺序加载。要解决此问题,请编写自己的运行程序(扩展com.googlecode.gwt.test.GwtRunner)并更改线程contextClassLoader的类加载器

import com.googlecode.gwt.test.GwtRunner;

    public class MyGwtRunner extends GwtRunner {

        static {
            URLClassLoader classLoader = (URLClassLoader) MyGwtRunner.class.getClassLoader();

            try {
                URL[] urls = getClassPath();
                ClassLoader cl = URLClassLoader.newInstance(urls, classLoader);
                Thread.currentThread().setContextClassLoader(cl);
            } catch (MalformedURLException e) {
                throw new IllegalStateException(e);
            }

        }

        public MyGwtRunner(Class<?> clazz) throws Throwable {
            super(clazz);
        }

        private static URL[] getClassPath() throws MalformedURLException {
            String classPath = System.getProperty("java.class.path");
            String pathSeparator = System.getProperty("path.separator");
            String[] array = classPath.split(pathSeparator);

            List<URL> files = new ArrayList<URL>();
            for (String a : array) {
                files.add(new File(a).toURI().toURL());
            }
            return files.toArray(new URL[files.size()]);
        }

    }

调试之后,我发现问题出在maven+jacoco上。如果您从eclipse(ecl emma插件)运行jacoco,您将看到代码覆盖率报告。我们需要该作业作为每夜jenkins构建作业的一部分运行,该作业使用sonar报告生成的覆盖率统计数据。你知道我们如何生成覆盖范围,然后在maven/sonar中重新使用它吗?由于eclipse中的org.apache.osgi框架存在问题,应用程序是在netbeans中构建的。使用此配置的sonar作业仍然存在同样的问题。不过,我将尝试让jacoco负责初始测试运行,并设置sonar以重用报告。一旦我尝试过,我就会发表评论。我使用我添加到上述问题中的pom设置尝试过,但我仍然看到相同的错误。我不得不使用额外的argline参数让jacoco尝试生成gwttest-utils单元测试的覆盖率。生成以成功结束,但缺少报告。。。我将检查maven-surefire-plugin使用最小类路径运行测试的原因。它运行GwtRunner类。但是GWT库尚未加载到类路径。这就产生了问题。我不知道,为什么这个场景只是,如果你用jacoco运行maven surefire插件。如果您从eclipse/手动使用jacoco,所有这些都可以正常工作。如果你在没有jacoco的情况下运行maven surefire插件,也可以很好地工作。谢谢你的帮助,我会看看我是否可以利用这些信息来制定解决方案。
import com.googlecode.gwt.test.GwtRunner;

    public class MyGwtRunner extends GwtRunner {

        static {
            URLClassLoader classLoader = (URLClassLoader) MyGwtRunner.class.getClassLoader();

            try {
                URL[] urls = getClassPath();
                ClassLoader cl = URLClassLoader.newInstance(urls, classLoader);
                Thread.currentThread().setContextClassLoader(cl);
            } catch (MalformedURLException e) {
                throw new IllegalStateException(e);
            }

        }

        public MyGwtRunner(Class<?> clazz) throws Throwable {
            super(clazz);
        }

        private static URL[] getClassPath() throws MalformedURLException {
            String classPath = System.getProperty("java.class.path");
            String pathSeparator = System.getProperty("path.separator");
            String[] array = classPath.split(pathSeparator);

            List<URL> files = new ArrayList<URL>();
            for (String a : array) {
                files.add(new File(a).toURI().toURL());
            }
            return files.toArray(new URL[files.size()]);
        }

    }
@GwtModule("com.my.module.GwtTestUtils")
@RunWith(MyGwtRunner.class)
public abstract class AbstractGwtJunit extends GwtTest { 
....
}