2011-03-15 24 views
0

我正在用tapestry-testify librairy做一些測試。但我有一個關於它的文檔的問題:http://tapestry.formos.com/nightly/tapestry-testify/testing-components.html我如何使用Tapestry Testify測試組件?

我想傳遞不同的值給我的組件的參數。 有人可以向我解釋我該怎麼做。

我與文檔中的項目結構相同。

myComponent.java

public class myComponent {  
    @Parameter 
    @Property 
    private String myParam; 
} 

myComponent.tml

<fieldset xmlns:t="http://tapestry.apache.org/schema/tapestry_5_1_0.xsd"> 
    <p>test ${myParam}</p> 
</fieldset> 

myComponentDemo.java

public class MyComponentDemo { 
    @Inject 
    @Service("myParam") 
    @Property 
    private String myParam;  
} 

myComponentDemo.tml

<html xmlns:t="http://tapestry.apache.org/schema/tapestry_5_1_0.xsd"> 
    <head> 
     <title>DayMonthYearDateInputTestPage</title> 
    </head> 
    <body> 
     <h1 id="h2">DayMonthYearDateInputTestPage</h1> 

     <div t:type="myC/MyComponent" t:id="myComponent" t:myParam="myParam"/> 
    </body> 
</html> 

myComponentTest.java

import Perso.monAppli.demo.DemoModule; 

import com.formos.tapestry.testify.core.ForComponents; 
import com.formos.tapestry.testify.core.TapestryTester; 
import com.formos.tapestry.testify.junit3.TapestryTest; 

public class MyComponentTest extends TapestryTest { 

    @ForComponents(value="myParam") 
    private String myParam; 

    private static final TapestryTester SHARED_TESTER = new TapestryTester("app", DemoModule.class); 

    public MyComponentTest() { 
     super(SHARED_TESTER); 
    } 

    @Test 
    public void testElementIsOnPage() { 
     Document page = tester.renderPage("demo/MyComponentDemo"); 
     System.out.println("### HTML " + page.getRootElement().getChildMarkup()); 
     Assert.assertTrue(page.getRootElement().getChildMarkup().contains("testMyParam")); 
    } 
} 

我必須傳遞價值,我的組件創建服務?

謝謝你的幫助。

+0

當ID測試該解決方案,我有這個錯誤消息: [錯誤] ioc.Registry服務ID「myParam」未由任何模塊定義。 – Gillespie59 2011-03-15 11:58:05

+0

您是否在AppModule.java類中爲myParam創建了服務? 或嘗試刪除@Inject註釋 – Milos 2011-10-09 20:13:18

回答

0

我不確定這個,但是您是否嘗試更改「myParam」的名稱?

例如:

myComponentDemo.java

@Inject 
@Service("myParamService") 
@Property 
private String myParamValue; 

myComponentDemo.tml

<div t:type="myC/MyComponent" t:id="myComponent" t:myParam="myParamValue"/> 

myComponentTest.java

@ForComponents("myParamService") 
private String myParam; 
相關問題