测试用例

package com.action;

import com.opensymphony.xwork2.ActionSupport;

public class HelloWorld extends ActionSupport {

 
 public static final String  MESSAGE="Start runing !!";
 
 public String execute() throws Exception
 {
  this.setMessage(MESSAGE);
  return SUCCESS;
 }
 
 private String message;

 public String getMessage() {
  return message;
 }

 public void setMessage(String message) {
  this.message = message;
 }
}

<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%@ taglib prefix="s" uri="/struts-tags" %>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
  <head>
  
    <title>Hello World!</title>
   
 
  </head>
 
  <body>
   
    <h2><s:property value="message"/></h2>
  </body>
</html>

<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE struts PUBLIC
    "-//Apache Software Foundation//DTD Struts Configuration 2.0//EN"
    "
http://struts.apache.org/dtds/struts-2.0.dtd">

<struts>
   <package name="struts2" extends="struts-default">  
        <action name="HelloWorld" class="com.action.HelloWorld">  
            <result  name="success">/helloworld.jsp</result> 
        </action> 
        <!-- Add your actions here --> 
    </package> 

  
  
</struts>

package com.test.action;

import com.action.HelloWorld;
import com.opensymphony.xwork2.ActionSupport;
import junit.framework.TestCase;

public class HelloWorldTest extends TestCase {
 
 @SuppressWarnings("static-access")
 public void testHelloWorld() throws Exception{
  
  HelloWorld helloworld=new HelloWorld();
  String result=helloworld.execute();
  
  this.assertTrue("expected a success result", ActionSupport.SUCCESS.equals(result));
  
  this.assertTrue("expected the default message!", HelloWorld.MESSAGE.equals(helloworld.getMessage()));
 }

}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值