2014-01-24 21 views
2

我想爲我的編譯器編寫一些測試,但無法通過錯誤。CompilationTestHelper找不到或者其訪問不受阻止

我正在遵循'實現DSL與Xtext和Xtend'由L. Bettini(偉大的書btw)的例子。我已經從https://github.com/LorenzoBettini/packtpub-xtext-book-examples下載了'entities'DSL的代碼,EntitiesGenerator.xtend的測試工作很好。

如果我寫了使用相同的代碼默認DSL(MyDsl)的測試中,我得到了一個錯誤:

  • org.eclipse.xtext.xbase.compiler.CompilationTestHelper cannot be resolved to a type

或者,如果我添加org.eclipse.xtext.xbase.junit (2.4.1)所需的插件列表中,我得到

  • Discouraged access: The type CompilationTestHelper is not accessible due to restriction on required project org.xtext.example.myDsl.tests

我可以允許訪問,但然後得到一個運行時錯誤呢。如果我嘗試添加org.eclipse.xtext.xbase.lib,則只有org.eclipse.xtext.xbase.lib.source出現在列表中。我不知道那很重要。無論如何,添加它並不會改變任何內容。

我需要做些什麼才能使它工作?

我使用Juno和Xtext 2.4.1,Java 1.7。

測試類的內容:

package org.xtext.example.myDsl.tests 

import com.google.inject.Inject 
import org.eclipse.xtext.junit4.InjectWith 
import org.eclipse.xtext.junit4.XtextRunner 
import org.eclipse.xtext.xbase.compiler.CompilationTestHelper // error here 
import org.xtext.example.myDsl.MyDslInjectorProvider 
import org.junit.Test 
import org.junit.runner.RunWith 

@RunWith(typeof(XtextRunner)) 
@InjectWith(typeof(MyDslInjectorProvider)) 
class MyDslGeneratorTest { 

    @Inject extension CompilationTestHelper 

    @Test 
    def void testGeneratedCode() { 
     ''' 
    Hello some1! 
    Hello some2! 
     '''.assertCompilesTo(
     '''some content''') 
    } 
} 

預先感謝您!

+0

僅供參考 - 消息,如「X是無法訪問的,由於所需項目ÿ限制「通常意味着您的項目被配置爲嚴格定義」正常「Java運行時包含的內容,並且它不喜歡您允許訪問其他用戶可能沒有的JAR的想法。即在項目屬性下,您將擁有類似「jre7」的內容,而不是本地計算機上的特定虛擬機。 –

+0

恐怕我不確定我在追隨。如果我將'org.example.entities.tests'(其源代碼不顯示警告)和'org.xtext.example.myDsl.test'的屬性進行比較,庫和順序和導出是相同的。 –

回答

1

xtext球員將可能被改變的東西標記爲不是api。這就是你得到這個警告的原因。無論如何它應該工作。 (雖然它的目的是僅用於XBASE語言)

PS:你已經添加依賴關係jdt.core太

+0

添加jdt.core訣竅,謝謝。測試運行時不會崩潰。警告仍然存在。 –