Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/spring/11.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/spring-boot/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Spring Kotlin测试从命令行失败,ClassNotFoundException但从IntelliJ工作_Spring_Spring Boot_Intellij Idea_Gradle_Kotlin - Fatal编程技术网

Spring Kotlin测试从命令行失败,ClassNotFoundException但从IntelliJ工作

Spring Kotlin测试从命令行失败,ClassNotFoundException但从IntelliJ工作,spring,spring-boot,intellij-idea,gradle,kotlin,Spring,Spring Boot,Intellij Idea,Gradle,Kotlin,我有一个Kotlin Spring Boot项目。它有一些测试,这些测试在IntelliJ中运行得很好,但当我在命令行中运行时,由于以下错误而失败 BUILD FAILED in 1m 12s 7 actionable tasks: 7 executed asarkar:license-report-kotlin$ ./gradlew clean test > Task :compileKotlin Using kotlin incremental compilation > T

我有一个Kotlin Spring Boot项目。它有一些测试,这些测试在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.springframework.context.annotation.AnnotationConfigApplicationContext@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.
到目前为止,我所尝试的:

  • build.gradle
    build.gradle.kts
    之间来回移动
  • 将Kotlin运行时添加到jar
    kotlinOptions.includeRuntime=true
  • 将包级别函数更改为对象中的函数
  • 我觉得奇怪的是:

  • 除了通常的Gradle
    build
    目录之外,还创建了一个
    out
    目录
  • 某些类/对象被编译为类文件,其名称以
    Kt
    结尾。我还没有找到任何押韵或理由,但我对科特林还是新手,所以我可能错过了一些东西 您的测试(或实际测试的类)做了一些奇怪的事情:它们以某种方式删除了包含测试类的
    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
        }
    
      }
    }
    
    如果你再做一次梯度测试

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

    检查您的测试以了解问题。

    您是对的。我的项目克隆了一个远程回购协议,然后构建它,在这个过程中,它以某种方式删除了
    build
    dir的内容。