Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

JUnit with Kotlin - This class does not have a constructor

I'm trying to implement testing with JUnit4 in my Kotlin application (as kotlin.test seems to be nonexistent in my Kotlin Runtime Library, and I don't now how to get it).
However, I am encountering an error simply by using the Test annotation.
That's my code:

import junit.framework.*

class IntTest {
    @Test    <------------- This line
    fun test1() {

    }
}

On the specified line, Eclipse gives an error message: "This class does not have a constructor".
I don't understand what is the problem. Which class doesn't have a constructor, and why should it have one?

like image 874
Neo Avatar asked Oct 18 '25 07:10

Neo


1 Answers

The junit.framework.Test is an interface and it's implementation has been deprecated since API 24. Since it's an interface hence it is causing the error

"This class does not have a constructor".

during annotation processing which is actually looking for a class.

Solution : Remove this and use import org.junit.Test;

like image 106
Pavneet_Singh Avatar answered Oct 19 '25 22:10

Pavneet_Singh



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!