How to write tests using JenkinsRule that make use of Jelly files and actions implemented in the test class itself

128 views
Skip to first unread message

René Scheibe

unread,
Jan 5, 2015, 7:59:30 AM1/5/15
to jenkin...@googlegroups.com
Hi,

can anybody give me some advice how to write tests that reference a Jelly file and implement actions in the test class?
(With HudsonTestCase this works fine but with JenkinsRule I have no idea.)

Example:
test/src/test/java/lib/form/NameRefTest.java

It references test/src/test/resources/lib/form/NameRefTest/test1.jelly and also implements doSubmitTest1().

Just converting it to use JenkinsRule instead of HudsonTestCase results in a HTTP 404 error.

I could not really find out how the Jelly files and actions of a test class are registered for a test Jenkins. I have seen that JenkinsRule and HudsonTestCase implement RootAction and add itself to Jenkin's actions. But in case of JenkinsRule this does not work as the test class itself does not inherit from JenkinsRule.

If I implement RootAction in the test itself and add it to Jenkin's actions in a @Before method I can get it to work. But something else than self has to be used for getUrlName() because the JenkinsRule registers itself already under self.

I think JenkinsRule has to be altered in a way that such tests don't have to implement RootAction and add it to Jenkin's actions.

What's your suggestion?

Cheers
René

Robert Sandell

unread,
Jan 5, 2015, 10:46:49 AM1/5/15
to jenkin...@googlegroups.com
I added it as a new @TestExtension in my test class. Not sure if its the most beautiful solution, but at least its not my ugliest hack ;)
In this case I have no jelly files to worry about, but its just a matter of moving them to the correct namespace I guess.

And in some ways it makes more sense to have the jelly files in separate test extensions as you then separate them from any @LocalData files. 


/B


--
You received this message because you are subscribed to the Google Groups "Jenkins Developers" group.
To unsubscribe from this group and stop receiving emails from it, send an email to jenkinsci-de...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/jenkinsci-dev/3cd3cdc7-9fee-4854-9b75-8201001a24cb%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.



--
Robert Sandell
Software Engineer
CloudBees Inc.

Jesse Glick

unread,
Jan 5, 2015, 6:03:18 PM1/5/15
to Jenkins Dev
On Mon, Jan 5, 2015 at 7:59 AM, René Scheibe <rene.s...@gmail.com> wrote:
> in case of JenkinsRule this does not work as the test class itself does not
> inherit from JenkinsRule.

You can either add the @WebMethod’s to a JenkinsRule subclass, or
factor out the RootAction as in Robert’s suggestion.

I will do the first change in NameRefTest as an example; validating here:

https://jenkins.ci.cloudbees.com/job/core/job/jenkins-core-validated-merge/334/
Reply all
Reply to author
Forward
0 new messages