2017-12-18 3 views
0

나는 Kotlin 및 LibGDX 프레임 워크를 사용하여 게임을 작성 중입니다. 나는 테스트를 처음 받았어. 몇 가지 기본 자습서를 통과하여 간단한 테스트를 만드는 법을 배웠습니다. 그리고 gradle을 구성하는 방법. 방금 클래스를 클릭하고 테스트 만들기를 선택합니다. 내가 프로젝트를 빌드 할 때미해결 된 참조 : junit

그러나, 나는 오류가 발생 :

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은 다음과 같습니다

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) 
    } 
} 

내가 Gradle을 JUnit을 참조하지 않는 것 같아요,하지만 난 모든 다음 명령. 어쩌면 나는 뭔가를 놓쳤을 것이다.

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" 
} 
+0

실제로 gradle이 junit을 실제로 다운로드 했습니까? 명령 행에서'./gradlew --refresh-dependencies'를 실행하여 그 의존성을 다시 검사하도록하십시오. – John

+0

'/ core/src/test/kotlin /'에'BagelTest.kt'를 넣으려고 했습니까? –

답변

0

내가 다음 단계로 libGdx +의 코 틀린에 대한 JUnit 테스트를 구성한 :

  1. 핵심 프로젝트 폴더에 '테스트'폴더를 만듭니다 - 그것은 테스트 코드 파일의 루트 폴더 될 것입니다 : 섹션 :

    project(":core") { 
        .... 
        dependencies { 
        ... 
        testCompile 'junit:junit:4.12' 
        testCompile "org.jetbrains.kotlin:kotlin-test-junit:$kotlinVersion" 
        } 
    } 
    
  2. : [프로젝트 루트]/코어/테스트

  3. 프로젝트 ("핵심")에 프로젝트의 주요 gradle.build 파일의 JUnit 종속성을 추가

  4. 는 테스트 소스는 설정 추가 [프로젝트 루트] 바로 'sourceSets.main.java.srcDirs = [ "SRC /"]'밑줄 /core/build.gradle 파일 :

    sourceSets.test.java.srcDirs = ["test/"] 
    
  5. 이제 [프로젝트 루트]/core/test 폴더가 녹색으로 강조 표시됩니다. 즉,이 폴더는 테스트 소스 디렉토리로 인식됩니다. 이제 예를 들어,이 간단한 junut 테스트와 .kt 파일을 배치 할 수 있습니다 :

    import org.junit.Test 
    import kotlin.test.assertEquals 
    
    class SimpleTest{ 
    
        @Test 
        fun testEquals(){ 
         var b=true 
         assertEquals(true,b) 
        } 
    } 
    
0

을 수행해야합니다

1) internal 단어를 제거 - 그것은

2

필요하지 않습니다) 간단한 assert 방법을 사용하여 테스트하는 것은 잘못되었습니다 - 메쉬를 사용하십시오 org.junit.Assert.*

관련 문제