viclovsky / swagger-coverage

Tool which generates full picture of coverage of API tests based on OAS (Swagger) v2 and v3
Apache License 2.0
197 stars 38 forks source link

Null Pointer Exception while integrating swagger coverage with karate framework #145

Open dtk72 opened 1 year ago

dtk72 commented 1 year ago

I'm submitting a ...

Error when running mvn clean test

java.lang.NullPointerException: Cannot invoke "java.nio.file.attribute.FileTime.toInstant()" because "this.minResultTime" is null

If the current behavior is a bug, please provide steps to reproduce, broken swagger specification and swagger-coverage-output:

Followed this code example provided in the README to generate a swagger coverage report after running karate tests for my own API:

import java.net.URI;
import com.github.viclovsky.swagger.coverage.karate.SwaggerCoverageRunner;
import com.intuit.karate.Results;
import org.junit.jupiter.api.Test;

public class CoverageReportRunner {

    @Test
    void testAll(){
        Results results = SwaggerCoverageRunner.path("classpath:some/path")
                .coverageDir("api-test-coverage")
                .swaggerSpec(URI.create("https://petstore3.swagger.io/api/v3/openapi.json"))
                .oas3()
                .outputJunitXml(true)
                .karateEnv("dev")
                .parallel(1);
    }
}

The error seems to arise when the code reaches .parallel(1)

Other information

Fresh-D101 commented 1 year ago

Hey! Could you please provide the full call stack for the error?

dtk72 commented 1 year ago

Hi! For sure,

java.lang.NullPointerException: Cannot invoke "java.nio.file.attribute.FileTime.toInstant()" because "this.minResultTime" is null
 at com.github.viclovsky.swagger.coverage.core.results.builder.prebuilder.GenerationStatisticsBuilder.build([GenerationStatisticsBuilder.java:60]
 at com.github.viclovsky.swagger.coverage.core.generator.Generator.lambda$run$1([Generator.java:49]
 at java.base/java.util.stream.ForEachOps$ForEachOp$OfRef.accept([ForEachOps.java:183]
 at java.base/java.util.stream.ReferencePipeline$2$1.accept([ReferencePipeline.java:179]
 at java.base/java.util.ArrayList$ArrayListSpliterator.forEachRemaining([ArrayList.java:1625]
 at java.base/java.util.stream.AbstractPipeline.copyInto([AbstractPipeline.java:484]
 at java.base/java.util.stream.AbstractPipeline.wrapAndCopyInto([AbstractPipeline.java:474]
 at java.base/java.util.stream.ForEachOps$ForEachOp.evaluateSequential([ForEachOps.java:150]
 at java.base/java.util.stream.ForEachOps$ForEachOp$OfRef.evaluateSequential([ForEachOps.java:173]
 at java.base/java.util.stream.AbstractPipeline.evaluate([AbstractPipeline.java:234]
 at java.base/java.util.stream.ReferencePipeline.forEach([ReferencePipeline.java:596]
 at com.github.viclovsky.swagger.coverage.core.generator.Generator.run([Generator.java:48]
 at com.github.viclovsky.swagger.coverage.karate.SwaggerCoverageRunner$SwaggerCoverageBuilder.generateReport([SwaggerCoverageRunner.java:126]
 at com.github.viclovsky.swagger.coverage.karate.SwaggerCoverageRunner$SwaggerCoverageBuilder.parallel([SwaggerCoverageRunner.java:163]
 at TestRunner.testAll([TestRunner.java:16]
 at java.base/java.util.ArrayList.forEach([ArrayList.java:1511]
 at java.base/java.util.ArrayList.forEach([ArrayList.java:1511]
Fresh-D101 commented 1 year ago

Hey, sorry for the late response, I'm super busy atm. I had a quick look at it, and I think I know what could be going on. Can you maybe share the log file?

dtk72 commented 1 year ago

No worries, I've attached the file: log4j.log

tsbirch commented 9 months ago

Hi, I've recently bumped into this same issue and would really like to try this module to check swagger coverage with Karate. Do you have any updates on this? Thank you!

Fresh-D101 commented 9 months ago

Hey guys, sorry I haven't gotten back to you on this issue. Can you also provide me with your log4j.log file and ideally a small reproduction project? I will try to take a look at this asap!

tsbirch commented 8 months ago

Hi, sorry I hadn't come back to this issue. I managed to prepare a small reproduction project (which I've attached), but wasn't able at first to get the error above.

I was finally able to reproduce the null pointer exception, but only if I change protocol to https in karate-config.js when the proxy is used (which is wrong):

if (karate.properties['proxy.port']){ console.log("Proxy server is used"); protocol = "https"; }

My main problem, though, is I'm not able to run tests using the proxy with https endpoints. I tried the workaround described here:

https://github.com/viclovsky/swagger-coverage/blob/master/swagger-coverage-karate/README.md#-the-problem-with-https-and-the-workaround

but with no success. Is it possible to work with https while using the proxy to measure swagger coverage?

Thanks again! myproject.zip

tdeverdiere commented 8 months ago

I 've got the same error and same stack than the one from @dtk72 when i upgrade version of karate 1.4.1 and other libraries:

Update karate version to 1.4.1

Update jackson to 2.5.13 to be compatible

Update other libraries:
- armeria 1.26.4
- classgraph 4.8.165
- netty 4.1.104
- thymeleaf 3.1.2.RELEASE
- wiremock 2.27.2

https://github.com/tdeverdiere/swagger-coverage/tree/update-karate

Error : "java.lang.NullPointerException: Cannot invoke "java.nio.file.attribute.FileTime.toInstant()" because "this.minResultTime" is null"

anneChen8888 commented 6 months ago

I got same issue, karate version is 1.4.0, swagger-coverage version is 1.5.0

Exception in thread "main" java.lang.NullPointerException: Cannot invoke "java.nio.file.attribute.FileTime.toInstant()" because "this.minResultTime" is null
        at com.github.viclovsky.swagger.coverage.core.results.builder.prebuilder.GenerationStatisticsBuilder.build(GenerationStatisticsBuilder.java:60)
        at com.github.viclovsky.swagger.coverage.core.generator.Generator.lambda$run$1(Generator.java:49)
        at java.base/java.util.stream.ForEachOps$ForEachOp$OfRef.accept(ForEachOps.java:183)
        at java.base/java.util.stream.ReferencePipeline$2$1.accept(ReferencePipeline.java:177)
        at java.base/java.util.ArrayList$ArrayListSpliterator.forEachRemaining(ArrayList.java:1625)
        at java.base/java.util.stream.AbstractPipeline.copyInto(AbstractPipeline.java:484)
        at java.base/java.util.stream.AbstractPipeline.wrapAndCopyInto(AbstractPipeline.java:474)
        at java.base/java.util.stream.ForEachOps$ForEachOp.evaluateSequential(ForEachOps.java:150)
        at java.base/java.util.stream.ForEachOps$ForEachOp$OfRef.evaluateSequential(ForEachOps.java:173)
        at java.base/java.util.stream.AbstractPipeline.evaluate(AbstractPipeline.java:234)
        at java.base/java.util.stream.ReferencePipeline.forEach(ReferencePipeline.java:497)
        at com.github.viclovsky.swagger.coverage.core.generator.Generator.run(Generator.java:48)
        at com.github.viclovsky.swagger.coverage.CommandLine.run(CommandLine.java:77)
        at java.base/java.util.Optional.orElseGet(Optional.java:362)
        at com.github.viclovsky.swagger.coverage.CommandLine.main(CommandLine.java:34)
anneChen8888 commented 6 months ago

I 've got the same error and same stack than the one from @dtk72 when i upgrade version of karate 1.4.1 and other libraries:

Update karate version to 1.4.1

Update jackson to 2.5.13 to be compatible

Update other libraries:
- armeria 1.26.4
- classgraph 4.8.165
- netty 4.1.104
- thymeleaf 3.1.2.RELEASE
- wiremock 2.27.2

https://github.com/tdeverdiere/swagger-coverage/tree/update-karate

Error : "java.lang.NullPointerException: Cannot invoke "java.nio.file.attribute.FileTime.toInstant()" because "this.minResultTime" is null"

Is the issue fixed on your side?

tdeverdiere commented 6 months ago

Hello No so i created an implementation of a Karate RuntimeHook: SwaggerCoverageRuntimeHook And use it in the Runner configuration:

        Results results = Runner.path("classpath:...")
                .outputCucumberJson(true)
                .outputJunitXml(true)
                .hook(new SwaggerCoverageRuntimeHook("target", "target/test-classes/swagger-coverage-config.json"))
                .reportDir(karateOutputPath)
                .parallel(1);

To write SwaggerCoverageRuntimeHook i mostly use the code from swagger-coverage-karate: SwaggerCoverageRunner#generateReport And i copy also the all class Generator from swagger-coverage-commandline/src/main/java/com/github/viclovsky/swagger/coverage/core/generator/Generator.java

I could give you the all code in my repo if you want

kwokfu commented 4 months ago

This looks like related to https://github.com/karatelabs/karate/issues/2048

kondababubalam commented 3 months ago

can you share repo @tdeverdiere

rc2201 commented 3 weeks ago

@tdeverdiere can you share the repo or provide any pointers on how to integrate this tool into Karate Runner? Thanks