[JIRA] (JENKINS-48466) Provide JUnit 5 support for JenkinsRule

2019-04-25 Thread ullrich.haf...@gmail.com (JIRA)
Title: Message Title


 
 
 
 

 
 
 

 
   
 Ulli Hafner commented on  JENKINS-48466  
 

  
 
 
 
 

 
 
  
 
 
 
 

 
  Re: Provide JUnit 5 support for JenkinsRule   
 

  
 
 
 
 

 
 Has someone the spare time to provide these ideas as a PR for the test harness?   
 

  
 
 
 
 

 
 
 

 
 
 Add Comment  
 

  
 

  
 
 
 
  
 

  
 
 
 
 

 
 This message was sent by Atlassian Jira (v7.11.2#711002-sha1:fdc329d)  
 

  
 

   





-- 
You received this message because you are subscribed to the Google Groups "Jenkins Issues" group.
To unsubscribe from this group and stop receiving emails from it, send an email to jenkinsci-issues+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


[JIRA] (JENKINS-48466) Provide JUnit 5 support for JenkinsRule

2019-04-25 Thread jenk...@t-8ch.de (JIRA)
Title: Message Title


 
 
 
 

 
 
 

 
   
 Thomas Weißschuh commented on  JENKINS-48466  
 

  
 
 
 
 

 
 
  
 
 
 
 

 
  Re: Provide JUnit 5 support for JenkinsRule   
 

  
 
 
 
 

 
 To get it to work with TestExtension I had to modify the JenkinsRule from Chris Hunt: 

 

  JenkinsRule(ParameterContext context,
  ExtensionContext extensionContext) {
  this.context = context;
  this.testDescription = Description.createTestDescription(
extensionContext.getTestClass().map(Class::getName).orElse(null),
extensionContext.getTestMethod().map(Method::getName).orElse(null)
  );
}
 

 To make it work with @RegisterExtension (to interact with the rule from @BeforeEach methods) the following works: 

 

public static class JenkinsExtension extends org.jvnet.hudson.test.JenkinsRule implements BeforeEachCallback, AfterEachCallback {

@Override
public void beforeEach(ExtensionContext context) throws Exception {
  this.testDescription = Description.createTestDescription(
context.getTestClass().map(Class::getName).orElse(null),
context.getTestMethod().map(Method::getName).orElse(null)
  );
  try {
before();
  } catch (Throwable throwable) {
throw new Exception(throwable);
  }
}

@Override
public void afterEach(ExtensionContext context) throws Exception {
  after();
}

@Override
public void recipe() throws Exception {
}
 

  
 

  
 
 
 
 

 
 
 

 
 
 Add Comment  
 

  
 

  
 
 
 
  
 

  
 
 
 
 

 
 This message was sent by Atlassian Jira (v7.11.2#711002-sha1:fdc329d)  
 

  

[JIRA] (JENKINS-48466) Provide JUnit 5 support for JenkinsRule

2018-11-23 Thread chrah...@gmail.com (JIRA)
Title: Message Title


 
 
 
 

 
 
 

 
   
 Chris Hunt commented on  JENKINS-48466  
 

  
 
 
 
 

 
 
  
 
 
 
 

 
  Re: Provide JUnit 5 support for JenkinsRule   
 

  
 
 
 
 

 
 I was able to get something started using a ParameterResolver, like so: 

 

package io.jenkins.plugins.websub;

import org.junit.jupiter.api.extension.AfterEachCallback;
import org.junit.jupiter.api.extension.ExtensionContext;
import org.junit.jupiter.api.extension.ParameterContext;
import org.junit.jupiter.api.extension.ParameterResolutionException;
import org.junit.jupiter.api.extension.ParameterResolver;
import org.jvnet.hudson.test.JenkinsRecipe;

import java.util.Optional;

public class TestUtils {
public static class JenkinsRule extends org.jvnet.hudson.test.JenkinsRule {
private final ParameterContext context;

JenkinsRule(ParameterContext context) {
this.context = context;
}

@Override
public void recipe() throws Exception {
Optional a = context.findAnnotation(JenkinsRecipe.class);
if (!a.isPresent()) return;
final JenkinsRecipe.Runner runner = a.get().value().newInstance();
recipes.add(runner);
tearDowns.add(() -> runner.tearDown(this, a.get()));
}
}

public static class JenkinsParameterResolver implements ParameterResolver, AfterEachCallback {
private static final String key = "jenkins-instance";
private static final ExtensionContext.Namespace ns =
ExtensionContext.Namespace.create(JenkinsParameterResolver.class);

@Override
public boolean supportsParameter(ParameterContext parameterContext, ExtensionContext extensionContext)
throws ParameterResolutionException {
return parameterContext.getParameter().getType().equals(JenkinsRule.class);
}

@Override
public Object resolveParameter(ParameterContext parameterContext, ExtensionContext extensionContext)
throws ParameterResolutionException {
JenkinsRule instance = extensionContext.getStore(ns).getOrComputeIfAbsent(
key, key -> new JenkinsRule(parameterContext), JenkinsRule.class);
try {
instance.before();
return instance;
} catch (Throwable t) {
throw new ParameterResolutionException(t.toString());
}
}

@Override
public void afterEach(ExtensionContext context) throws Exception {
JenkinsRule rule = context.getStore(ns).remove(key, JenkinsRule.class);
if (rule != null)
rule.after();
}
}
}
 

 Used like 

 

package io.jenkins.plugins.websub;

import hudson.model.FreeStyleBuild;
import hudson.model.FreeStyleProject;
import hudson.tasks.Shell;
import org.apache.commons.io.FileUtils;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.ExtendWith;

@ExtendWith(TestUtils.JenkinsParameterResolver.class)
public class TestWebSubTrigger {
@Test
void testJenkinsParameterResolver(TestUtils.JenkinsRule j) throws Exception {
FreeStyleProject project = j.createFreeStyleProject();
project.getBuildersList().add(new Shell("echo hello"));

[JIRA] (JENKINS-48466) Provide JUnit 5 support for JenkinsRule

2018-02-27 Thread mko...@gmail.com (JIRA)
Title: Message Title


 
 
 
 

 
 
 

 
   
 Mike Kobit commented on  JENKINS-48466  
 

  
 
 
 
 

 
 
  
 
 
 
 

 
  Re: Provide JUnit 5 support for JenkinsRule   
 

  
 
 
 
 

 
 Another possibility would be to implement ExternalResource to enable usage of https://junit.org/junit5/docs/current/user-guide/#migrating-from-junit4-rule-support   
 

  
 
 
 
 

 
 
 

 
 
 Add Comment  
 

  
 

  
 
 
 
  
 

  
 
 
 
 

 
 This message was sent by Atlassian JIRA (v7.3.0#73011-sha1:3c73d0e)  
 
 

 
   
 

  
 

  
 

   





-- 
You received this message because you are subscribed to the Google Groups "Jenkins Issues" group.
To unsubscribe from this group and stop receiving emails from it, send an email to jenkinsci-issues+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.