2017-03-17 55 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