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;
}
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.
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.
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.
Before proxy.execute()
, the executeResult
should be set false
value: proxy.setExecuteResult(false)
.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With