2017-07-17 115 views
0

我有一个Kotlin弹簧启动项目here。它有一些测试,从IntelliJ运行得很好,但是当我从命令行运行时,失败并出现以下错误。Kotlin测试失败从命令行与ClassNotFoundException但从IntelliJ工作

BUILD FAILED in 1m 12s 
7 actionable tasks: 7 executed 
asarkar:license-report-kotlin$ ./gradlew clean test 

> Task :compileKotlin 
Using kotlin incremental compilation 

> Task :compileTestKotlin 
Using kotlin incremental compilation 

> Task :test 

2017-07-16 21:43:06.345 INFO 2956 --- [  Thread-13] s.c.a.AnnotationConfigApplicationContext : Closing org.spring[email protected]54fa5525: startup date [Sun Jul 16 21:42:04 PDT 2017]; root of context hierarchy 
org.abhijitsarkar.ApplicationTest > testEndToEnd FAILED 
    java.lang.AssertionError at ApplicationTest.kt:83 

org.abhijitsarkar.service.GradleAgentTest > initializationError FAILED 
    java.lang.ClassNotFoundException 

org.abhijitsarkar.service.JGitAgentTest > initializationError FAILED 
    java.lang.ClassNotFoundException 

org.abhijitsarkar.service.LinkVerifierTest > initializationError FAILED 
    java.lang.ClassNotFoundException 

4 tests completed, 4 failed 


FAILURE: Build failed with an exception. 

我试过到目前为止:

  1. 来回穿梭的build.gradlebuild.gradle.kts之间。
  2. 将Kotlin运行时添加到罐子kotlinOptions.includeRuntime = true
  3. 将包级函数更改为对象中的函数。

我发现奇怪:

  1. out目录中除了通常的摇篮build目录中创建。
  2. 某些类/对象被编译为名称以Kt结尾的类文件。我还没有找到任何押韵或原因,但我还是Kotlin的新手,所以我可能会错过一些东西。

回答

0

您的测试(或实际测试的类)做了一些奇怪的事情:它们以某种方式删除包含测试类的build文件夹的内容。

看到这一点,请尝试以下操作:

./gradlew clean testClasses 
find build # You get a full list of all main and test classes 
./gradlew clean testClasses test 
find build # You get a very limited list of resources in the build-folder (must be somehow modified by your code) 

如果禁用所有的测试,只是添加以下(只是用于测试目的)在那里:

import io.kotlintest.matchers.* 
import io.kotlintest.specs.* 

class MyTests : StringSpec() { 
    init { 

    "length should return size of string" { 
     "hello".length shouldBe 5 
    } 

    } 
} 

如果再次gradle这个 - 测试它,

./gradlew clean testClasses test 
find build # all resources again available 

检查您的测试的问题。

+0

你说得对。我的项目克隆了一个远程仓库,然后构建它,并且在这个过程中它以某种方式删除了'build'目录的内容。 –

相关问题