2017-03-17 93 views
0

我嘗試寫tapestry 5.4頁面渲染JUnit測試:Tapestry頁面JUnit測試

import org.apache.tapestry5.test.PageTester; 

public class LoadTest { 
    private final String PAGE_NAME = "Login"; 
    private final String APP_NAME = ""; 
    private final String context = "src/main/webapp"; 
    private PageTester tester; 

    @Before 
    public void init() { 
     String appPackage = "hu.webapp"; 
     tester = new PageTester(appPackage, APP_NAME, context, AppModule.class); 
    } 

    @Test 
    public void confirmIndexIsLoaded() { 
     Document document = new Document(); 
     document = tester.renderPage(PAGE_NAME); 
     assertNotNull(document); 
    } 
} 

但我得到了一個RuntimeException,和它說Request was not handled: 'Login' may not be a valid page name.

但是,這是在我的webapp一個工作頁面,並呈現良好。

有人有任何想法(s)測試有什麼問題,或者有人能給我看一個類似的工作測試代碼嗎?

在此先感謝!

回答

1

一般來說,只有當你通知錯誤的package你的頁面包時纔會發生這種情況。看看(我的作品):

import org.apache.tapestry5.test.PageTester; 

public class LoadTest { 
    private final String PAGE_NAME = "Login"; // It has to be right too! 
    private final String APP_NAME = "app"; // Where was your app name? 
    private final String context = "src/main/webapp"; // Is that path right in your project? 
    private PageTester tester; 

    @Before 
    public void init() { 
     String appPackage = "hu.webapp"; // Check if that's really correct!!! 
     tester = new PageTester(appPackage, APP_NAME, context); 
    } 

    @Test 
    public void confirmIndexIsLoaded() { 
     Document document = tester.renderPage(PAGE_NAME); 
     assertNotNull(document); 
    } 
} 

另外,檢查你app的名字,它應該被配置在你的web.xml文件作爲掛毯過濾器,像,如:

<filter> 
    <filter-name>app</filter-name> 
    <filter-class>org.apache.tapestry5.TapestryFilter</filter-class> 
</filter> 

<filter-mapping> 
    <filter-name>app</filter-name> 
    <url-pattern>/*</url-pattern> 
    <dispatcher>REQUEST</dispatcher> 
    <dispatcher>ERROR</dispatcher> 
</filter-mapping> 
+0

嘿!感謝你的回答。其實缺乏關於掛毯測試的信息..我讀了一些文章..但是每篇文章都提出了不同的東西..所以最後他們困惑了我..所以它變得非常有種「黑盒測試」..反正也是 「上下文」是指我的項目的絕對路徑還是相對路徑? – LakiGeri

+0

我想通了! 'private final String PAGE_NAME =「Login」; private final String APP_NAME =「app」; private final String context =「src/main」;' 我離開了「appPackage」的「.ui」結尾 thx幫助 – LakiGeri

+0

不客氣! :) – bosco