2017-08-25 76 views
0

使用JUnit我已经使用JUnit使用Groovy类加载器

class GroovyJunitTest { 
    @Test 
    void test() { 
    println this.class.getClassLoader().toString() 
    } 
} 

一个简单的Groovy测试类此打印出

[email protected] 

这意味着Java类加载器使用。

我使用Intellij IDE和Gradle测试运行测试。在这两种情况下都是相同的结果。

有没有办法配置JUnit使用Groovy类加载器?

+0

你是如何运行它?从任何IDE?或构建工具? – Rao

+0

@Rao刚刚更新了我的问题 – lolotron

+0

请看看这是否有帮助 - https://stackoverflow.com/questions/42102/using-different-classloaders-for-different-junit-tests – Rao

回答

0

一旦我遇到同样的问题,我用https://github.com/bitstrings/junit-clptr 加载我的custom classloader

注意:这不再由crator支持,但对我来说它确实解决了问题。无论如何,如果重要的是信任外部来源,你可以把它作为一个灵感,并定义你自己的注释,让你选择你的自定义类加载器