gwt-test-utils unit fail when run with jacoco

本秂侑毒 提交于 2019-12-05 10:08:43

As I mentioned in comments libraries are loaded in different order for jacoco with maven-surefire-plugin. To solve this problem write your own runner (extends com.googlecode.gwt.test.GwtRunner) and change classloader for thread 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()]);
        }

    }

In your tests override GwtRunner by MyGwtRunner

@GwtModule("com.my.module.GwtTestUtils")
@RunWith(MyGwtRunner.class)
public abstract class AbstractGwtJunit extends GwtTest { 
....
}
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!