Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Unit test fail when result type is tile

I am trying to test my action classes with the jUnit plugin. The action looks like this:

@Action(value = "default", results = {
    @Result(name = "success", type="tiles", location = "login") })
public String defaultAction() {
    return SUCCESS;
}

When I call the proxy.execute(), the test crashes. I am probably forgetting something that makes my test run with tiles, but i have no clue about what that may be. I get the following stack trace:

java.lang.NullPointerException
at org.apache.struts2.views.tiles.TilesResult.doExecute(TilesResult.java:105)
at org.apache.struts2.dispatcher.StrutsResultSupport.execute(StrutsResultSupport.java:186)
at com.opensymphony.xwork2.DefaultActionInvocation.executeResult(DefaultActionInvocation.java:373)
...

When I change the action as below, the test executes normally:

@Action(value = "default", results = {
    @Result(name = "success", type="redirectAction", location = "login") })
public String defaultAction() {
    return SUCCESS;
}
like image 533
Hayk Avatar asked Jun 27 '11 12:06

Hayk


People also ask

What are some examples of unit testing characteristics?

Characteristics of a good unit testFast: It isn't uncommon for mature projects to have thousands of unit tests. Unit tests should take little time to run. Milliseconds. Isolated: Unit tests are standalone, can be run in isolation, and have no dependencies on any outside factors such as a file system or database.

What should be tested in unit testing?

The purpose of a unit test in software engineering is to verify the behavior of a relatively small piece of software, independently from other parts. Unit tests are narrow in scope, and allow us to cover all cases, ensuring that every single part works correctly.

Why is it important for unit tests to run quickly?

The speed of detecting non-working code depends on the tools used for continuous integration. Tests can be set to run either a one-time check at a certain time interval or can be run immediately in real-time to review changes. In short, unit tests help developers detect problems immediately, then fix them quickly.


1 Answers

Before proxy.execute(), the executeResult should be set false value: proxy.setExecuteResult(false).

like image 152
Hayk Avatar answered Nov 09 '22 01:11

Hayk