specsy icon indicating copy to clipboard operation
specsy copied to clipboard

tried to take the context before it was prepared

Open jqno opened this issue 6 years ago • 1 comments

I'm trying Specsy, but when I run mvn clean test I get the following error, and I don't know how to proceed.

org.apache.maven.surefire.util.SurefireReflectionException: java.lang.reflect.InvocationTargetException; nested exception is java.lang.reflect.InvocationTargetException: null
java.lang.reflect.InvocationTargetException
	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.apache.maven.surefire.util.ReflectionUtils.invokeMethodWithArray(ReflectionUtils.java:189)
	at org.apache.maven.surefire.booter.ProviderFactory$ProviderProxy.invoke(ProviderFactory.java:165)
	at org.apache.maven.surefire.booter.ProviderFactory.invokeProvider(ProviderFactory.java:85)
	at org.apache.maven.surefire.booter.ForkedBooter.runSuitesInProcess(ForkedBooter.java:115)
	at org.apache.maven.surefire.booter.ForkedBooter.main(ForkedBooter.java:75)
Caused by: java.lang.IllegalStateException: tried to take the context before it was prepared
	at org.specsy.bootstrap.ContextDealer.take(ContextDealer.java:20)
	at org.specsy.java.JavaSpecsy.<init>(JavaSpecsy.java:16)
	at nl.jqno.something.PlumbingTest.<init>(PlumbingTest.java:5)
	at java.base/jdk.internal.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
	at java.base/jdk.internal.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62)
	at java.base/jdk.internal.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
	at java.base/java.lang.reflect.Constructor.newInstance(Constructor.java:490)
	at java.base/java.lang.Class.newInstance(Class.java:584)
	at org.apache.maven.surefire.junit.PojoTestSet.<init>(PojoTestSet.java:63)
	at org.apache.maven.surefire.junit.JUnit3Provider.createTestSet(JUnit3Provider.java:107)
	at org.apache.maven.surefire.junit.JUnit3Provider.invoke(JUnit3Provider.java:97)
	... 9 more

I have the following dependencies in my pom:

<dependency>
  <groupId>org.specsy</groupId>
  <artifactId>specsy-java</artifactId>
  <version>2.3.3</version>
  <scope>test</scope>
</dependency>
<dependency>
  <groupId>org.specsy</groupId>
  <artifactId>specsy-junit</artifactId>
  <version>2.3.3</version>
  <scope>test</scope>
</dependency>

My test looks like this:

package nl.jqno.something;

import org.specsy.java.JavaSpecsy;

public class PlumbingTest extends JavaSpecsy {

    public void run() {
        spec("Main class is accessible in tests despite modularization", () -> {
            System.out.println(Main.getHerokuAssignedPort());
        });
    }
}

If I rename it to PlumbingSpec (as suggested in the documentation), it doesn't get picked up at all.

Also, IntelliJ doesn't notice there's a test at all.

What can I do to make it work?

jqno avatar Mar 11 '19 05:03 jqno

Also possibly relevant: I'm running on JDK 11.

jqno avatar Mar 11 '19 07:03 jqno