Unit testing pages or components
Wiki Markup |
---|
{float:right|background=#eee} {infocontentbylabel:title=Related Articles} * [Integration Testing with Selenium|Test] {info|showLabels=false|showSpace=false|space=@self|labels=testing} {float} |
You can easily unit test a certain page or a component. Follow the simple tasks below.
...
In order to unit test a page, you'll need to create an instance of PageTester. It acts as both the browser and the servlet container so that you can use it to drive your page. As it is not a real servlet container, you need to tell it the same information as you would in web.xml: 1.
- Your application package.
...
- Your filter name. This is used to load your Tapestry IoC module only. If you have none, you can pass an empty string or anything to it.
...
- The folder acting as your context root. This is used to locate your templates (if they're put there).Here is an example (using TestNG, but you're free to use JUnit or anything else):
Code Block | ||||
---|---|---|---|---|
| ||||
public class MyTest extends Assert { @Test public void test1() { String appPackage = "org.example.app"; String appName = "App1"; // App1Module.java has configured some services. PageTester tester = new PageTester(appPackage, appName, "src/main/webapp"); } } |
...