How to test abstract class in Java with JUnit?

后端 未结 10 1240
野趣味
野趣味 2020-11-27 04:46

I am new to Java testing with JUnit. I have to work with Java and I would like to use unit tests.

My problem is: I have an abstract class with some abstract methods.

10条回答
  •  予麋鹿
    予麋鹿 (楼主)
    2020-11-27 05:14

    I would create a jUnit inner class that inherits from the abstract class. This can be instantiated and have access to all the methods defined in the abstract class.

    public class AbstractClassTest {
       public void testMethod() {
       ...
       }
    }
    
    
    class ConcreteClass extends AbstractClass {
    
    }
    

提交回复
热议问题