使用@category注释运行在Kotlin中编写的junit测试

时间:2017-02-19 13:57:22

标签: junit kotlin

我有一个问题。 是否有可能注释用Kotlin编写的Junit测试, @Category在接口名称中有空格? 我想要这样的东西:

@Test
@Category(`Kotlin interface`::class)
fun `Test with spaces`() {

现在我收到一个例外

1 个答案:

答案 0 :(得分:0)

即使在Kotlin中允许使用带空格的类名,它们也会违反命名约定,即PascalCase或UpperCamelCase。我刚用最新的JUnit 4对它进行了测试,但它不起作用。

"C:\Program Files\Java\jdk1.8.0_131\bin\java" -ea -Didea.test.cyclic.buffer.size=1048576 "-javaagent:C:\Program Files\JetBrains\IntelliJ IDEA Community Edition 2017.3\lib\idea_rt.jar=56217:C:\Program Files\JetBrains\IntelliJ IDEA Community Edition 2017.3\bin" -Dfile.encoding=UTF-8 -classpath "C:\Program Files\JetBrains\IntelliJ IDEA Community Edition 2017.3\lib\idea_rt.jar" com.intellij.rt.execution.CommandLineWrapper C:\Users\foo\AppData\Local\Temp\idea_classpath com.intellij.rt.execution.junit.JUnitStarter -ideVersion5 -junit4 com.foo.bar.http.BarHTTPApplicationTest,systemInfoGET

java.lang.reflect.GenericSignatureFormatError: Signature Parse error: expected '<' or ';' but got  
    Remaining input:  Tests;

    at sun.reflect.generics.parser.SignatureParser.error(SignatureParser.java:124)
    at sun.reflect.generics.parser.SignatureParser.parsePackageNameAndSimpleClassTypeSignature(SignatureParser.java:348)
    at sun.reflect.generics.parser.SignatureParser.parseClassTypeSignature(SignatureParser.java:310)
    at sun.reflect.generics.parser.SignatureParser.parseFieldTypeSignature(SignatureParser.java:289)
    at sun.reflect.generics.parser.SignatureParser.parseFieldTypeSignature(SignatureParser.java:283)
    at sun.reflect.generics.parser.SignatureParser.parseTypeSignature(SignatureParser.java:485)
    at sun.reflect.generics.parser.SignatureParser.parseTypeSig(SignatureParser.java:188)
    at sun.reflect.annotation.AnnotationParser.parseSig(AnnotationParser.java:436)
    at sun.reflect.annotation.AnnotationParser.parseClassValue(AnnotationParser.java:420)
    at sun.reflect.annotation.AnnotationParser.parseClassArray(AnnotationParser.java:724)
    at sun.reflect.annotation.AnnotationParser.parseArray(AnnotationParser.java:531)
    at sun.reflect.annotation.AnnotationParser.parseMemberValue(AnnotationParser.java:355)
    at sun.reflect.annotation.AnnotationParser.parseAnnotation2(AnnotationParser.java:286)
    at sun.reflect.annotation.AnnotationParser.parseAnnotations2(AnnotationParser.java:120)
    at sun.reflect.annotation.AnnotationParser.parseAnnotations(AnnotationParser.java:72)
    at java.lang.reflect.Executable.declaredAnnotations(Executable.java:599)
    at java.lang.reflect.Executable.declaredAnnotations(Executable.java:597)
    at java.lang.reflect.Executable.getDeclaredAnnotations(Executable.java:588)
    at java.lang.reflect.Method.getDeclaredAnnotations(Method.java:630)
    at java.lang.reflect.AccessibleObject.getAnnotations(AccessibleObject.java:207)
    at org.junit.runners.model.FrameworkMethod.getAnnotations(FrameworkMethod.java:187)
    at org.junit.runners.model.TestClass.addToAnnotationLists(TestClass.java:84)
    at org.junit.runners.model.TestClass.scanAnnotatedMembers(TestClass.java:66)
    at org.junit.runners.model.TestClass.<init>(TestClass.java:57)
    at org.junit.runners.ParentRunner.createTestClass(ParentRunner.java:88)
    at org.junit.runners.ParentRunner.<init>(ParentRunner.java:83)
    at org.junit.runners.BlockJUnit4ClassRunner.<init>(BlockJUnit4ClassRunner.java:65)
    at org.junit.internal.builders.JUnit4Builder.runnerForClass(JUnit4Builder.java:10)
    at org.junit.runners.model.RunnerBuilder.safeRunnerForClass(RunnerBuilder.java:59)
    at org.junit.internal.builders.AllDefaultPossibilitiesBuilder.runnerForClass(AllDefaultPossibilitiesBuilder.java:26)
    at org.junit.runners.model.RunnerBuilder.safeRunnerForClass(RunnerBuilder.java:59)
    at org.junit.internal.requests.ClassRequest.getRunner(ClassRequest.java:33)
    at org.junit.internal.requests.FilterRequest.getRunner(FilterRequest.java:36)
    at com.intellij.junit4.JUnit4IdeaTestRunner.startRunnerWithArgs(JUnit4IdeaTestRunner.java:49)
    at com.intellij.rt.execution.junit.IdeaTestRunner$Repeater.startRunnerWithArgs(IdeaTestRunner.java:47)
    at com.intellij.rt.execution.junit.JUnitStarter.prepareStreamsAndStart(JUnitStarter.java:242)
    at com.intellij.rt.execution.junit.JUnitStarter.main(JUnitStarter.java:70)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:498)
    at com.intellij.rt.execution.CommandLineWrapper.main(CommandLineWrapper.java:65)


Process finished with exit code -1

所以,也许有一天会有可能,但现在不行。