Junit 5 - No ParameterResolver registered for parameter

后端 未结 6 3211
长情又很酷
长情又很酷 2021-02-05 01:41

Source : JUnit 5, Eclipse 4.8 , Selenium

I can write up and execute Selenium script without any special test framework but I wanted to use Junit 5 (because we have depe

相关标签:
6条回答
  • 2021-02-05 01:56

    I had both @Test and @ParameterizedTest annotating the same method. I removed the former.

    0 讨论(0)
  • 2021-02-05 02:01

    I got this error because my test needed my Spring Boot server to be running first, so that dependency injection using @Autowired would get executed. I added these annotations:

    @Transactional
    @ExtendWith(SpringExtension.class)
    @SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT, classes = Server.class)
    public MyTestClass () {
    ...
    
    }
    
    0 讨论(0)
  • 2021-02-05 02:04

    This error appears when you try to use both @Test and @ParameterizedTest in the same test class. Removing @Test annotation will resolve the issue.

    0 讨论(0)
  • 2021-02-05 02:10

    Annotating test class with @ExtendWith(MockitoExtension.class) worked for me

    0 讨论(0)
  • 2021-02-05 02:16

    As Marc Philipp mentioned in his comment, you need to ensure that JUnit Jupiter can instantiate your test class.

    For your particular scenario, you'll need to remove your custom constructor that accepts a WebDriver.

    Then you have two options:

    1. Create the WebDriver on your own -- for example, in an @BeforeAll or @BeforeEach method.
    2. Use an extension such as Selenium Jupiter to help manage the WebDriver for you.
    0 讨论(0)
  • 2021-02-05 02:22

    I also got ParameterResolutionException with JUnit 5.

    org.junit.jupiter.api.extension.ParameterResolutionException: 
    No ParameterResolver registered for parameter [int[] arg0] in constructor (public my_package.MyClass(int[]))
    

    I had written @Test methods inside the class I was testing.

    This error could be fixed in two ways:

    1) Either replacing import org.junit.jupiter.api.Test with import org.junit.Test, or

    2) Writing tests in a separate TestClass.

    0 讨论(0)
提交回复
热议问题