0

how to write Junit test case for ZK controller?

asked 2019-08-01 05:37:45 +0800

Pavan89 gravatar image Pavan89
1

how to inject session in zk controller from testclass which is @wirevariable in controller.

delete flag offensive retag edit

1 Answer

Sort by ยป oldest newest most voted
0

answered 2019-08-01 12:57:02 +0800

cor3000 gravatar image cor3000
4671 2 7
ZK Team

updated 2019-08-01 12:58:25 +0800

internally ZK calls Selectors.wireVariables(...)

https://www.zkoss.org/javadoc/latest/zk/org/zkoss/zk/ui/select/Selectors.html#wireVariables-org.zkoss.zk.ui.Component-java.lang.Object-java.util.List-

As you can see from the arguments you can provide a variable resolver that returns a mocked session object when requested. However looking at the actual source code, there's a lot going on especially ZK assuming it lives in a running application (so expect a bit more mocking to be necessary, maybe your scenario is simple enough and "just works" smoothly).

https://github.com/zkoss/zk/blob/master/zk/src/org/zkoss/zk/ui/select/Selectors.java#L130 https://github.com/zkoss/zk/blob/master/zk/src/org/zkoss/zk/ui/select/Selectors.java#L353

If you want an integrated test solution please checkout ZATs our testing library especially for testing pages/controllers/viewmodels without requiring a browser. It simulates user interactions in order to test controller/view model logic.

--> https://www.zkoss.org/product/zats

link publish delete flag offensive edit
Your answer
Please start posting your answer anonymously - your answer will be saved within the current session and published after you log in or create a new account. Please try to give a substantial answer, for discussions, please use comments and please do remember to vote (after you log in)!

[hide preview]

Question tools

Follow
2 followers

RSS

Stats

Asked: 2019-08-01 05:37:45 +0800

Seen: 5 times

Last updated: Aug 01

Support Options
  • Email Support
  • Training
  • Consulting
  • Outsourcing
Learn More