Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Introduce migration support for JUnit 4's Parameterized Runner #715

Closed
3 tasks
LiamClark opened this issue Mar 9, 2017 · 9 comments
Closed
3 tasks

Introduce migration support for JUnit 4's Parameterized Runner #715

LiamClark opened this issue Mar 9, 2017 · 9 comments

Comments

@LiamClark
Copy link
Contributor

LiamClark commented Mar 9, 2017

Overview

Introduce migration support for JUnit 4's @RunWith(Parameterized.class).

@marcphilipp mentioned through email that it would be nice to have an extension in junit-jupiter-migration-support that allows tests to be run that were originally written with JUnit 4 using the Parameterized runner.

What this would look like:

import static org.junit.Assert.assertEquals;

import java.util.Arrays;
import java.util.Collection;
import org.junit.jupiter.api.TestTemplate;
import org.junit.jupiter.api.extension.ExtendWith;
import org.junit.jupiter.migrationsupport.extensions.Parameterized;
import org.junit.runners.Parameterized.Parameters;

@ExtendWith(ParameterizedExtension.class)
public class FibonacciTest {

    @Parameters
    public static Collection<Object[]> data() {
        return Arrays.asList(new Object[][] {     
                 { 0, 0 }, { 1, 1 }, { 2, 1 }, { 3, 2 }, { 4, 3 }, { 5, 5 }, { 6, 8 }  
           });
    }

    private int input;

    private int expected;

    public FibonacciTest(int input, int expected) {
        this.input= input;
        this.expected= expected;
    }

    @TestTemplate
    public void test() {
        assertEquals(expected, Fibonacci.compute(input));
    }
}
public class Fibonacci {
    public static int compute(int n) {
    	int result = 0;
    	
        if (n <= 1) { 
        	result = n; 
        } else { 
        	result = compute(n - 1) + compute(n - 2); 
        }
        
        return result;
    }
}

If everybody agrees this is a good idea, I would like to tackle this issue.

Deliverables

  • Introduce ParameterizedExtension extension in junit-jupiter-migration-support.
  • An updated section in the user guide.
  • Document in release notes.
@gaganis
Copy link
Contributor

gaganis commented Mar 9, 2017

When thinking about this in isolation, I would like to point out a small thing.

Maybe it would be better to name Parameterized to something different so it more easily distinguishable from the JUnit4 runner.

Maybe ParameterizedExtension?

What does the team think?

@sbrannen
Copy link
Member

sbrannen commented Mar 9, 2017

ParameterizedExtension is more inline with naming conventions in JUnit Jupiter.

@sbrannen
Copy link
Member

sbrannen commented Mar 9, 2017

If everybody agrees this is a good idea, I would like to tackle this issue.

It's definitely an interesting idea, and I imagine people would find it useful. So if you have the time and inclination, feel free to take a shot at it.

@sbrannen sbrannen changed the title Migration support for @RunWith(Parameterized.class) Migration support for @RunWith(Parameterized.class) Aug 19, 2017
@sbrannen sbrannen changed the title Migration support for @RunWith(Parameterized.class) Introduce migration support for @RunWith(Parameterized.class) Aug 19, 2017
@sbrannen sbrannen changed the title Introduce migration support for @RunWith(Parameterized.class) Introduce migration support for JUnit 4's Parameterized Runner Aug 19, 2017
@sbrannen sbrannen added this to the General Backlog milestone Aug 19, 2017
@TatyanaSnigiriova
Copy link

TatyanaSnigiriova commented Sep 5, 2019

@LiamClark, @sbrannen Hi, how can I use ParameterizedExtension.class in my project? I added dependency junit-jupiter-api (5.1.0-RC1) and junit-jupiter-engine (5.0.3), but I still can't use it to @ExtendWith :c
https://github.com/delftswa2017/junit5/tree/parameterized-migration-support

@sbrannen
Copy link
Member

sbrannen commented Sep 5, 2019

@TatyanaSnigiriova, the ParameterizedExtension was never released.

However, you can view the (now closed) work in progress in PR #723.

@TatyanaSnigiriova
Copy link

TatyanaSnigiriova commented Sep 5, 2019

@sbrannen Could you help me?
Is there a method by which I can realize running multiple tests on each test data set? I need to read the data, then conduct several tests on this data, then get the next set of data and conduct the same test methods on them. So far I see only one way: in @ParameterizedTest prepare the data and write in it all the test methods that I want to to carry out on this data. Is there a better way?

@ParameterizedTest 
@CsvFileSource(resources = "/data.csv", numLinesToSkip = 1) 
void runTestMethodsOnTheFollowingDataset (String lastName, String firstName) {
    /*
        Form a 'Human'
    */
    signedUpForEnglishCoursesTest(person);
    startLearningTest(person);
    speakEnglishTest(person);
    leaveCorsesTest(person); 
}

Thank you for your attention

@sbrannen
Copy link
Member

sbrannen commented Sep 6, 2019

@TatyanaSnigiriova

Thanks for getting in touch, but it feels like this is a question that would be better suited to Stack Overflow. We prefer to use the issue tracker only for bugs and enhancements. Feel free to update this issue with a link to the re-posted question (so that other people can find it) or add some more details if you feel this is a genuine bug.

Having said that, if you post the link back here, we'll see if we can help answer it.

@stale
Copy link

stale bot commented May 13, 2021

This issue has been automatically marked as stale because it has not had recent activity. Given the limited bandwidth of the team, it will be automatically closed if no further activity occurs. Thank you for your contribution.

@stale stale bot added the status: stale label May 13, 2021
@stale
Copy link

stale bot commented Jun 3, 2021

This issue has been automatically closed due to inactivity. If you have a good use case for this feature, please feel free to reopen the issue.

@stale stale bot closed this as completed Jun 3, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants