2017-08-25 77 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支持,但對我來說它確實解決了問題。無論如何,如果重要的是信任外部來源,你可以把它作爲一個靈感,並定義你自己的註釋,讓你選擇你的自定義類加載器