Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Null Pointer exception due to Step Class not able to be Injected/Resolved... #2150

Closed
pats-john opened this issue Jul 4, 2020 · 10 comments
Closed

Comments

@pats-john
Copy link

pats-john commented Jul 4, 2020

I am getting the following error.

java.lang.NullPointerException
at com.test.functional.employee.EmployeeServiceTest.testSuccessfullPost(EmployeeServiceTest.java:22)
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.base/java.lang.reflect.Method.invoke(Method.java:566)
at org.junit.platform.commons.util.ReflectionUtils.invokeMethod(ReflectionUtils.java:686)
at org.junit.jupiter.engine.execution.MethodInvocation.proceed(MethodInvocation.java:60)

My Runner File Looks like this

package com.test.functional.employee;

import com.testfunctional.employee.steps.EmployeeSteps;

import net.serenitybdd.junit.runners.SerenityRunner;
import net.thucydides.core.annotations.Narrative;
import net.thucydides.core.annotations.Steps;
import org.junit.jupiter.api.Test;
import org.junit.runner.RunWith;

@RunWith(SerenityRunner.class)
@Narrative(text={"In order to test that the Employee Service is working properly",
"As a tester",
"I want to be able to execute the tests for various endpoints"})
public class EmployeeServiceTest {

@Steps
EmployeeSteps cftOrCrime;

@Test
public void testSuccessfullPost () {
    cftOrCrime.invokeEmployee();

}

}

My Step Files look like this

package uk.gov.hmcts.futurehearings.hmi.functional.employee.steps;

import net.thucydides.core.annotations.Step;

public class EmployeeSteps {

private String actor;

@Step
public void invokeEmployee () {
   System.out.println("The value is sorted");
}

}

My dependencies are

//functionalTestCompile ("org.springframework.boot:spring-boot-starter-web")
//functionalTestCompile group: 'net.serenity-bdd', name: 'serenity-rest-assured', version: versions.serenity
functionalTestCompile group: 'net.serenity-bdd', name: 'serenity-core', version: versions.serenity
functionalTestCompile group: 'net.serenity-bdd', name: 'serenity-junit', version: versions.serenity
//functionalTestCompile group: 'net.serenity-bdd', name: 'serenity-spring', version: versions.serenity
functionalTestCompile group: 'net.serenity-bdd', name: 'serenity-screenplay', version :versions.serenity
//functionalTestCompile group: 'net.serenity-bdd', name: 'serenity-single-page-report', version: versions.serenityreporter
functionalTestCompile "ch.qos.logback:logback-classic:1.2.3"
functionalTestCompile "org.assertj:assertj-core:3.8.0"

functionalTestImplementation group: 'io.rest-assured', name: 'xml-path', version: versions.restAssured
functionalTestImplementation group: 'io.rest-assured', name: 'json-path', version: versions.restAssured
//functionalTestImplementation group: 'org.skyscreamer', name: 'jsonassert', version: '1.5.0'

with versions

def versions = [
junit : '5.6.2',
junitPlatform : '1.6.2',
reformLogging : '5.1.5',
springBoot : springBoot.class.package.implementationVersion,
springfoxSwagger: '2.9.2',
serenity : '2.2.9',
restAssured : '4.2.0',
serenityreporter : '2.1.4',
assertJ : '3.8.0',
logbackVersion : '1.2.3'
]

I am using Java 11 and Junit 5...

On running my test from the command line with the info option,I seem to get the following...

22:16:32.157 [Test worker] DEBUG org.apache.http.impl.conn.BasicClientConnectionManager - Releasing connection org.apache.http.impl.conn.ManagedClientConnectionImpl@3519571a
22:16:32.158 [Test worker] INFO net.serenitybdd.rest.decorators.request.RequestSpecificationDecorated - No BaseStepListener, GET not registered.

What could I be missing?Can someone help?????

@wakaleo
Copy link
Member

wakaleo commented Jul 6, 2020

Are you trying to run the Serenity test with JUnit 5?

@pats-john
Copy link
Author

Yes I am and I got it running on Junit 4....I found that later on...

Thanks for the response...I missed your comment.Apologies for the delay...

@pats-john
Copy link
Author

This ticket can be closed if there is no further support for Junit 5...

@wakaleo
Copy link
Member

wakaleo commented Jul 8, 2020

Yep, JUnit 5 runners aren't supported yet, so you need to run it using the legacy JUnit 4 mode.

@wakaleo wakaleo closed this as completed Jul 8, 2020
@pats-john
Copy link
Author

Thanks for the confirmation...

@Dvoreth
Copy link

Dvoreth commented Sep 21, 2021

I encountered this in Serenity 2.6.0 when using JUnit5 . I'm assuming it simply doesn't work yet since the JUnit 5 support is still in beta?

@wakaleo
Copy link
Member

wakaleo commented Sep 21, 2021

Are you using the serenity-junit5 module?

@Dvoreth
Copy link

Dvoreth commented Sep 21, 2021

Yes :)

    <dependency>
        <groupId>net.serenity-bdd</groupId>
        <artifactId>serenity-junit5</artifactId>
        <version>2.6.0</version>
        <scope>test</scope>
    </dependency>

@wakaleo
Copy link
Member

wakaleo commented Sep 21, 2021

@Dvoreth
Copy link

Dvoreth commented Sep 22, 2021

Thank you so so much for that example project! I was missing the line
<junit.jupiter.extensions.autodetection.enabled>true</junit.jupiter.extensions.autodetection.enabled>
in my maven-failsafe-plugin configuration in the pom.xml. With this line it works. Thanks again!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants