如何使用 Tapestry Testify 测试组件

发布于 2024-10-22 17:31:52 字数 2412 浏览 4 评论 0原文

我正在使用 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

唠甜嗑 2024-10-29 17:31:52

我不确定这一点,但是您是否尝试更改“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;

I'm not sure of this, but did you try to change name of "myParam"?

For instance:

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;
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文