Best junit code snippet using org.junit.experimental.categories.CategoryValidator.validateAnnotatedMethod
Source:CategoryValidatorTest.java
...55 FrameworkMethod method = new TestClass(CategoryTest.class).getAnnotatedMethods(After.class).get(0);56 testAndAssertErrorMessage(method, "@After can not be combined with @Category");57 }58 private void testAndAssertErrorMessage(FrameworkMethod method, String expectedErrorMessage) {59 List<Exception> errors = new CategoryValidator().validateAnnotatedMethod(method);60 assertThat(errors.size(), is(1));61 Exception exception = errors.get(0);62 assertThat(exception.getMessage(), is(expectedErrorMessage));63 }64 @Test65 public void errorIsNotAddedWhenCategoryIsNotCombinedWithIllegalCombination() throws NoSuchMethodException {66 FrameworkMethod method = new FrameworkMethod(CategoryTest.class.getMethod("methodWithCategory"));67 List<Exception> errors = new CategoryValidator().validateAnnotatedMethod(method);68 assertThat(errors.size(), is(0));69 }70}...
LambdaTest also has a detailed JUnit tutorial explaining its features, importance, advanced use cases, best practices, and more to help you get started with running your automation testing scripts.
Here are the detailed JUnit testing chapters to help you get started:
You can also check out our JUnit certification if you wish to take your career in Selenium automation testing with JUnit to the next level.
Get 100 minutes of automation test minutes FREE!!