【六袆 - Java】2022年 Struts2单元测试;struts2官方案例;



1.官方文档

在这里插入图片描述

2.给出的测试模块

  • 模块名称:unit-testing
package org.apache.struts.register.action;


import com.opensymphony.xwork2.ActionProxy;
import com.opensymphony.xwork2.ActionSupport;
import org.apache.struts2.StrutsTestCase;
import org.junit.Test;

public class RegisterTest extends StrutsTestCase {

	@Test
	public void testExecuteValidationPasses() throws Exception {
		
		request.setParameter("personBean.firstName", "Bruce");
		
		request.setParameter("personBean.lastName", "Phillips");
		
		request.setParameter("personBean.email", "bphillips@ku.edu");
		
		request.setParameter("personBean.age", "19");
			
		ActionProxy actionProxy = getActionProxy("/register.action") ;
		
		Register action = (Register) actionProxy.getAction();
		
		assertNotNull("The action is null but should not be.", action);

		String result = actionProxy.execute();
		
		assertEquals("The execute method did not return " + ActionSupport.SUCCESS + " but should have.", ActionSupport.SUCCESS, result);

	} 

}

  • successful
2022-10-26 00:07:14,231 INFO  [main] ognl.OgnlUtil (OgnlUtil.java:274) - OGNL Expression Max Length enabled with 256.
2022-10-26 00:07:14,258 WARN  [main] ognl.OgnlUtil (OgnlUtil.java:845) - Working in devMode, using devMode excluded classes and packages!

Process finished with exit code 0

3.遇到的问题

3.1 编译问题

<build>

        <plugins>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-compiler-plugin</artifactId>
                <version>3.10.1</version>
                <configuration>
                    <source>1.8</source>
                    <target>1.8</target>
                </configuration>
            </plugin>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-javadoc-plugin</artifactId>
                <version>3.4.1</version>
                <configuration>
                    <doclint>none</doclint>
                </configuration>
            </plugin>
        </plugins>
  • 官方案例使用的是jdk11版本进行编译的,按需修改

3.2单独一个模块进行测试,运行高效

  • 在父工程的pom.xml中,需要测试哪个模块,就打开,如图

在这里插入图片描述


在这里插入图片描述

3.5.必须引入插件

<!-- https://mvnrepository.com/artifact/org.apache.struts/struts2-junit-plugin -->
<dependency>
    <groupId>org.apache.struts</groupId>
    <artifactId>struts2-junit-plugin</artifactId>
    <version>2.3.31</version>
    <scope>test</scope>
</dependency>

  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值