Junit - java.lang.Exception: no managed methods

I am doing a tutorial on running server test cases using the driver class. An error message appeared on the Eclipse error bar: java.lang.Exception: no startup methods. The error message occurred when the driver class tried to run the exceptionTesting class.

Based on pm this post: java.lang.exception no runnable methods junit . It seems that the @Test annotation should be used in a test class or update the Junit Jar file to the current version to solve the problem.

Junit Jar File Version: 4.11

Read my code and let me know what kind of modification I have to do to avoid the error message. Thanks!

Driver Class:

import org.junit.runner.*; import org.junit.runners.Suite; @RunWith(Suite.class) @Suite.SuiteClasses({ basicAnnotation.class, personTest.class, exceptionTesting.class }) public class UnitTestDriver { } 

exceptionTesting class

 import org.junit.*; import org.junit.Test; public class exceptionTesting { public class junitTest2{ @Test (expected = ArithmeticException.class) public void divisionWithException(){ int i = 1/0; } } } 
+4
source share
1 answer

The problem is that junitTest2 is nested inside the exceptionTesting exception. You have two options for solving the problem:

1) Get rid of the inner class having your tests in the top level class:

 import org.junit.*; import org.junit.Test; public class exceptionTesting { @Test (expected = ArithmeticException.class) public void divisionWithException(){ int i = 1/0; } } 

2) Let your top-level class indicate that the tests are wrapped, and make your inner class static:

 import org.junit.*; import org.junit.Test; @RunWith(Enclosed.class) public class exceptionTesting { public static class junitTest2{ @Test (expected = ArithmeticException.class) public void divisionWithException(){ int i = 1/0; } } } 

Unless you have a reason for the inner class, the best option is # 1. Also note that in Java, the convention should start with classes with uppercase names. Thus, exceptionTesting will become ExceptionTesting.

+3
source

Source: https://habr.com/ru/post/1483359/


All Articles