jglick: are you sure that this is actually a duplicate?
JENKINS-33925 is about unit-testing Jenkinsfiles without interacting with a "real" Jenkins at all.
The requirement testing a global library is IMVHO partly a different usecase, where you might want to "integration test" the methods from your global library actually interacting with the Jenkins you are running this on. While this is not nicely isolated, it might give you useful feedback if your methods are actually correctly interacting with the Jenkins, especially when it comes to CPS transformed code.
While you can just write assertions using if statements and failing the build using error if something is not what you expect it to be, this is a lot more cumbersome than e.g. using JUnit, and does not give you the same feedback.
- your tests will abort if you call error
- if you use assert instead, your tests will just as well abort (unless you write some kind of harness yourself)
- assert in CPS-transformed code is much less useful than "normal" Groovy assert - it does not give you the values of the whole expression
- you don't get Junit-style test reports (again unless you report those yourself)
- the JenkinsRule-approach mentioned in JENKINS-33925 looked promising to me, however you only get to check the logs and the result of the build, so it is rather a black-box (or gray-box) test, as you cannot query the exact values your methods return (or you would have to parse them out of the log or using some other hacks)
It would be really nice to have some kind of support here..