如何使用 Tapestry Testify 测试组件
我正在使用 Tapestry-testify 库进行一些测试。但我对其文档有疑问:http://tapestry.formos。 com/nightly/tapestry-testify/testing-components.html
我想将不同的值传递给我的组件的参数。 有人可以向我解释一下我该怎么做吗?
我的项目结构与文档中的相同。
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"));
}
}
我是否必须创建一个服务来将值传递给我的组件?
感谢您的帮助。
I am doing some tests with the tapestry-testify librairy. But I have a question about its documentation : http://tapestry.formos.com/nightly/tapestry-testify/testing-components.html
I would like to pass different value to a parameter of my component.
Could someone explain to me how can i do that.
I have the same project structure as in the documentation.
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"));
}
}
Do I have to create a service for passing value to my component ?
Thank you for your help.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我不确定这一点,但是您是否尝试更改“myParam”的名称?
例如:
myComponentDemo.java
myComponentDemo.tml
myComponentTest.java
I'm not sure of this, but did you try to change name of "myParam"?
For instance:
myComponentDemo.java
myComponentDemo.tml
myComponentTest.java