Skip to content

Simplify test idioms to build a project and assert the status #43

@jglick

Description

@jglick

What problem are you trying to solve?

Some plugins have many functional test assertions using an overly verbose idiom for triggering a build of a test project, waiting for the build to complete, and then checking the result of the build. There are simpler idioms available in the JenkinsRule test utility, and we can also apply centralized improvements to make this workflow more reliable (removing nondeterministic aspects).

What precondition(s) should be checked before applying this recipe?

Any Jenkins plugins using JenkinsRule (a default test dependency), whether explicitly as a @Rule, or as a parameter passed into a method when the @Rule is actually something else (RestartableJenkinsRule, JenkinsSessionRule, RealJenkinsRule).

Describe the situation before applying the recipe

Some idiom variants:

rule.assertBuildStatusSuccess(project1.scheduleBuild2(0).get());
FreeStyleBuild build2 = project2.scheduleBuild2(0, new Cause.UserIdCause()).get();
rule.assertBuildStatus(Result.FAILURE, build2);

Describe the situation after applying the recipe

The corresponding simpler versions:

rule.buildAndAssertSuccess(project1);
FreeStyleBuild build2 = rule.buildAndAssertStatus(Result.FAILURE, project2);

Have you considered any alternatives or workarounds?

Regexp search and replace?!

Any additional context

N/A

Are you interested in contributing this recipe to OpenRewrite?

TBD

Metadata

Metadata

Assignees

No one assigned

    Labels

    recipeRequests for new automated code changes

    Type

    No type

    Projects

    Status

    Recipes Wanted

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions