课程: Complete Guide To Java Testing with JUnit 5 & Mockito

今天就学习课程吧!

今天就开通帐号,24,600 门业界名师课程任您挑!

Parameterized tests with EnumSource in JUnit 5

Parameterized tests with EnumSource in JUnit 5

- [Instructor] Let's practice using parameterized tests in JUnit 5. Here, we have a sample enum class that has some repetitive logic. It runs several tests that assert whether or not a given role has write permissions. Let's simplify this using parameterization. Instead of having four tests, one for each user role, we'll have two. One that verifies those with write permission, and the other that verifies those without write permission. These will take in a user role. For those with write permission, we'll assert that they do have write permission with the assertTrue. And for those without, we'll assert that this returns false to ensure they do not have write permission. Each of these will be a parameterized test, so we'll use the ParameterizedTest annotation. Now, in order to use this annotation, we'll need to update our POM file with the JUnit Jupiter params artifact. We'll go to our dependencies and add a new dependency. The groupId will be the same as our JUnit Jupiter API module…

内容