Create an account

Very important

  • To access the important data of the forums, you must be active in each forum and especially in the leaks and database leaks section, send data and after sending the data and activity, data and important content will be opened and visible for you.
  • You will only see chat messages from people who are at or below your level.
  • More than 500,000 database leaks and millions of account leaks are waiting for you, so access and view with more activity.
  • Many important data are inactive and inaccessible for you, so open them with activity. (This will be done automatically)


Thread Rating:
  • 179 Vote(s) - 3.36 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Unresolved reference: junit

#1
I'm writing game using Kotlin and LibGDX framework. I'm new to testing. I have passed some basic tutorial how to create simple test. And how to configure gradle. I just clicked on class and choose create test.

But, when i try to build project i get an error:

e: /Users/maximternovtsi/bagel/core/src/test/test/BagelTest.kt: (1, 12): Unresolved reference: junit
e: /Users/maximternovtsi/bagel/core/src/test/test/BagelTest.kt: (2, 12): Unresolved reference: junit
e: /Users/maximternovtsi/bagel/core/src/test/test/BagelTest.kt: (6, 6): Unresolved reference: Test
e: /Users/maximternovtsi/bagel/core/src/test/test/BagelTest.kt: (8, 9): Unresolved reference: Assertions
e: /Users/maximternovtsi/bagel/core/src/test/test/BagelTest.kt: (11, 6): Unresolved reference: Test
e: /Users/maximternovtsi/bagel/core/src/test/test/BagelTest.kt: (13, 9): Unresolved reference: Assertions

FAILURE: Build failed with an exception.

* What went wrong:
Execution failed for task ':core:compileKotlin'.

BagelTest looks like this:


import org.junit.jupiter.api.Test

import org.junit.jupiter.api.BeforeEach


internal class BagelTest {


@BeforeEach
internal fun setUp() {
}

@Test
internal fun passes() {
assert(true)
}
}

I guess that gradle doesn't see junit, but i followed all instructions. Maybe i missed something.



buildscript {
repositories {

jcenter()
google()
}
dependencies {
classpath 'com.android.tools.build:gradle:3.0.0'
classpath 'org.multi-os-engine:moe-gradle:1.4.0'
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:1.1.51"
}
}

allprojects {
apply plugin: "eclipse"
apply plugin: "idea"

version = '1.0'
ext {
appName = "Bagel"
gdxVersion = '1.9.8'
junitJupiterVersion = '5.0.2'
}

repositories {
mavenLocal()
mavenCentral()
maven { url "https://oss.sonatype.org/content/repositories/snapshots/" }
maven { url "https://oss.sonatype.org/content/repositories/releases/" }
}
}

project(":desktop") {
apply plugin: "kotlin"

dependencies {
compile project(":core")
compile "com.badlogicgames.gdx:gdx-backend-lwjgl:$gdxVersion"
compile "com.badlogicgames.gdx:gdx-platform:$gdxVersion:natives-desktop"
compile "com.badlogicgames.gdx:gdx-box2d-platform:$gdxVersion:natives-desktop"
compile "com.badlogicgames.gdx:gdx-freetype-platform:$gdxVersion:natives-desktop"
}
}

project(":android") {
apply plugin: "android"
apply plugin: "kotlin-android"

configurations { natives }

dependencies {
compile project(":core")
compile "org.jetbrains.kotlin:kotlin-stdlib:1.1.51"
compile "com.badlogicgames.gdx:gdx-backend-android:$gdxVersion"
natives "com.badlogicgames.gdx:gdx-platform:$gdxVersion:natives-armeabi"
natives "com.badlogicgames.gdx:gdx-platform:$gdxVersion:natives-armeabi-v7a"
natives "com.badlogicgames.gdx:gdx-platform:$gdxVersion:natives-arm64-v8a"
natives "com.badlogicgames.gdx:gdx-platform:$gdxVersion:natives-x86"
natives "com.badlogicgames.gdx:gdx-platform:$gdxVersion:natives-x86_64"
compile "com.badlogicgames.gdx:gdx-box2d:$gdxVersion"
natives "com.badlogicgames.gdx:gdx-box2d-platform:$gdxVersion:natives-armeabi"
natives "com.badlogicgames.gdx:gdx-box2d-platform:$gdxVersion:natives-armeabi-v7a"
natives "com.badlogicgames.gdx:gdx-box2d-platform:$gdxVersion:natives-arm64-v8a"
natives "com.badlogicgames.gdx:gdx-box2d-platform:$gdxVersion:natives-x86"
natives "com.badlogicgames.gdx:gdx-box2d-platform:$gdxVersion:natives-x86_64"
compile "com.badlogicgames.gdx:gdx-freetype:$gdxVersion"
natives "com.badlogicgames.gdx:gdx-freetype-platform:$gdxVersion:natives-armeabi"
natives "com.badlogicgames.gdx:gdx-freetype-platform:$gdxVersion:natives-armeabi-v7a"
natives "com.badlogicgames.gdx:gdx-freetype-platform:$gdxVersion:natives-arm64-v8a"
natives "com.badlogicgames.gdx:gdx-freetype-platform:$gdxVersion:natives-x86"
natives "com.badlogicgames.gdx:gdx-freetype-platform:$gdxVersion:natives-x86_64"
}
}

project(":core") {
apply plugin: "kotlin"

/*kotlin {
experimental {
coroutines 'enable'
}
}*/

sourceSets.test.java.srcDirs = ["/test"]

dependencies {
compile "com.badlogicgames.gdx:gdx:$gdxVersion"
compile "com.badlogicgames.gdx:gdx-box2d:$gdxVersion"
compile "com.badlogicgames.gdx:gdx-freetype:$gdxVersion"
compile "org.jetbrains.kotlin:kotlin-stdlib:1.1.51"
compile "com.badlogicgames.ashley:ashley:1.7.3"

testCompile("org.junit.jupiter:junit-jupiter-api:${junitJupiterVersion}")
// testCompile "org.mockito:mockito-core:2.2.7"
}
}

tasks.eclipse.doLast {
delete ".project"
}



Reply

#2
I've configured junit tests for libGdx+kotlin by following steps:

1. Create 'test' folder in the core project folder - it will be the root folder for test code files: [project-root]/core/test

2. Add junit dependencies in project main gradle.build file to the project(":core") section:

project(":core") {
....
dependencies {
...
testCompile 'junit:junit:4.12'
testCompile "org.jetbrains.kotlin:kotlin-test-junit:$kotlinVersion"
}
}

3. Add test source set in [project-root]/core/build.gradle file, right under the 'sourceSets.main.java.srcDirs = [ "src/" ]' line:

sourceSets.test.java.srcDirs = ["test/"]
4. Now the [project-root]/core/test folder will be highlighted with green, which means that this folder is recognized as test source directory. Now you can place there a .kt file with simple junut test, for example:

import org.junit.Test
import kotlin.test.assertEquals

class SimpleTest{

@Test
fun testEquals(){
var b=true
assertEquals(true,b)
}
}
Reply

#3
You should:

1) remove `internal` word - it is not required

2) using simple `assert` method in tests is wrong - use methonds from `org.junit.Assert.*`
Reply

#4
In my case problem was I didn't import

androidTestImplementation "org.jetbrains.kotlin:kotlin-test-junit:$kotlin_version"

Update May 2020: This should be placed in build.gradle's `dependencies { }`. As of Android Studio version 4 and current gradle version, the variable should be named $*version_kotlin* for gradle to properly re-sync.
Reply

#5
I am using Android Studio 4.0 version and there is (test) package already in the android project it's a default package , I have put my kotlin test file there and there is no problem with it. I didn't run the file yet but there are no import errors for junit etc. I hope this is helpful.
Reply

#6
in app module's `build.gradle`

replace `testImplementation`
with
`androidTestImplementation`
Reply

#7
First make sure that the kotlin version defined in `build.gradle.kts (project)` is the same as the [selected in the compiler][1].

plugins {
kotlin("jvm") version "1.4.21" apply false
}

If these versions are matting and still not working then proceed with the following steps:
___

1. Delete all cache folders including:

- .gradle
- .idea

2. Invalidate Caches / Restart...

3. Open any gradle file (settings.gradle.kts)

4. In the IDE at the top right click in `Link Gradle project`

[![Link Gradle project][2]][2]

5. Finally, specifies that JUnit 5 should be used to execute the tests

### build.gradle.kts

tasks.test {
useJUnitPlatform()
}

_Note_: This behavior can be defined [by gradle][3] or [from the IDE][4]
___


It is very likely that if it worked and you have the dependencies it is a cache problem or gradle configuration.

GL


[1]:

[To see links please register here]

[2]:

[3]:

[To see links please register here]

[4]:

[To see links please register here]

Reply



Forum Jump:


Users browsing this thread:
1 Guest(s)

©0Day  2016 - 2023 | All Rights Reserved.  Made with    for the community. Connected through