Lovegiver
Lovegiver

Reputation: 451

Starting with IntelliJ and Gradle : how to do jUnit tests?

Good evening,

because I want to initiate myself to LibGDX, I recently gave a try to IntelliJ Idea IDE and Gradle instead of my old Eclipse-Maven habits.

I have to recognize that such a change is not easy because I really don't find anything.

To start learning I created a project with a simple Pojo and also a unit test class.

enter image description here

I have no error in the editor, both Pojo and jUnit seem OK, but when I launch the unit test, I get such errors :

enter image description here

Can someone help me understand what's going wrong ?

EDIT : build.gradle file content :

plugins {
    id 'java'
}

group 'com.citizenweb.training'
version '1.0-SNAPSHOT'

repositories {
    mavenCentral()
}

dependencies {
    testCompile group: 'junit', name: 'junit', version: '4.12'
    // https://mvnrepository.com/artifact/org.projectlombok/lombok
    compile group: 'org.projectlombok', name: 'lombok', version: '1.18.16'

}

Thanx by advance.

Upvotes: -1

Views: 240

Answers (1)

M.Ricciuti
M.Ricciuti

Reputation: 12126

It seems you did not configure lombok dependencies properly: your test classes cannot see lombok-generated stuff (getters, setters, build). Lombok is based on annotation processor so you need to declare following dependencies in your build.gradle :

ext {
    lombokVersion = "1.18.6"
}

    dependencies {
        
        // Lombok
        compileOnly ("org.projectlombok:lombok:${lombokVersion}")
        annotationProcessor ("org.projectlombok:lombok:${lombokVersion}")
    
        // to make lombok available for test classes
        testCompileOnly ("org.projectlombok:lombok:${lombokVersion}")
        testAnnotationProcessor ("org.projectlombok:lombok:${lombokVersion}")

        testImplementation("junit:junit:4.12")
    }

Upvotes: 0

Related Questions