Override a pytest parameterized functions name

You’re looking for the ids argument of pytest.mark.parametrize: list of string ids, or a callable. If strings, each is corresponding to the argvalues so that they are part of the test id. If callable, it should take one argument (a single argvalue) and return a string or return None. Your code would look like @pytest.mark.parametrize( … Read more

JUnit 5 @MethodSource in nested class

@TestInstance(PER_CLASS) You may select the “single test instance per class” mode annotating the nested class with @TestInstance(TestInstance.Lifecycle.PER_CLASS): class ColorTest { @Nested @TestInstance(TestInstance.Lifecycle.PER_CLASS) class Inner { @ParameterizedTest @MethodSource(“colors”) void blue(Color color, int blue) { Assertions.assertEquals(color.getBlue(), blue); } Stream<Arguments> colors() { return Stream.of( Arguments.of(Color.BLACK, 0), Arguments.of(Color.GRAY, 128), Arguments.of(Color.BLUE, 255) ); } } } When using this mode, … Read more

When using JUnit’s @Parameterized, can I have some tests still run only once [duplicate]

You could structure your test with the Enclosed runner. @RunWith(Enclosed.class) public class TestClass { @RunWith(Parameterized.class) public static class TheParameterizedPart { @Parameters public static Object[][] data() { … } @Test public void someTest() { … } @Test public void anotherTest() { … } } public static class NotParameterizedPart { @Test public void someTest() { … } … Read more

Excluding a non param test in parameterized test class

JUnit 5 As of Junit 5.0.0 you can now annotate your test methods with @ParameterizedTest. So no need for inner classes. There are many ways to supply the arguments to the parameterized test apart from ValueSource as shown below. See the official junit user guide for details: import org.junit.jupiter.api.Test; import org.junit.jupiter.api.ParameterizedTest; import org.junit.jupiter.params.provider.ValueSource; public class … Read more

Create multiple parameter sets in one parameterized class (junit)

This answer is similar to Tarek’s one (the parametrized part), although I think it is a bit more extensible. Also solves your problem and you won’t have failed tests if everything is correct: @RunWith(Parameterized.class) public class CalculatorTest { enum Type {SUBSTRACT, ADD}; @Parameters public static Collection<Object[]> data(){ return Arrays.asList(new Object[][] { {Type.SUBSTRACT, 3.0, 2.0, 1.0}, … Read more

Changing names of parameterized tests

This feature has made it into JUnit 4.11. To use change the name of parameterized tests, you say: @Parameters(name=”namestring”) namestring is a string, which can have the following special placeholders: {index} – the index of this set of arguments. The default namestring is {index}. {0} – the first parameter value from this invocation of the … Read more

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)