4

I have a problem, I would like to pass the test method to send a request using the GET method and POST. I used parameterization, but I get information java.lang.Exception: Method simpleMessage should have no parameters

  @Test
    @ParameterizedTest
    @ValueSource(strings = {"true", "false"})
    public void simpleMessage (boolean isPost) {
        verifyIdOdpEqual(isPost,1243, "message");
    }
Charles
  • 139
  • 2
  • 3
  • 7
  • I have no idea what you are trying to do, but the test is like a void function you first run the function with the annotation and inside the function you tell it to run other functions like "simpleMessage (boolean isPost) " function. Basically create @Test testPostFunction(){ Add starting condition. do something in simpleMessage(boolean) function and assert if the simpleMessage result worked or failed. the name "verifyIdOdpEqual" does not tell me quit clearly what the function does. – Jasper Lankhorst Jan 28 '20 at 22:23

2 Answers2

16

I don't quite understand what you trying to achieve as well but you have few problems with your code:

  1. By presence of @ParameterizedTest and @ValueSource I assume you using JUnit 5. At the same time looks like you marked your method with annotation from JUnit 4 (because only in that case you will get an exception with the text you quoted).
  2. @Test is redundant when the method is annotated with @ParametrizedTest.

You have 2 options how to fix all of the above:

  1. If you want to use junit5 then you need to remove @Test annotation and make sure that your tests are launched by a runner that supports JUnit 5 (more info).

    Example:

    package test;
    
    import org.junit.jupiter.params.ParameterizedTest;
    import org.junit.jupiter.params.provider.ValueSource;
    
    public class TestTest {
    
        @ParameterizedTest
        @ValueSource(booleans =  {true, false})
        public void test(boolean data) {
            System.out.println(data);
        }
    }
    
  2. If you want to use JUnit 4 then you need to remove @ParameterizedTest and @ValueSource annotations and rewrite your test to use parametrized runner (more info).

Mikhail
  • 211
  • 1
  • 7
1

Simply remove the line @Test out of your code

Nguyen Minh Hien
  • 455
  • 7
  • 10