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

Initialization Error leaves test results empty #793

Closed
cleanerx opened this Issue Nov 29, 2017 · 1 comment

Comments

Projects
None yet
2 participants
@cleanerx

cleanerx commented Nov 29, 2017

I'm using Eclipse:
Spock should be showing an test case error in the Junit View if a test initialization fails. It currently shows a stacktrace in the Eclipse console. In Junit this is shown as test case error.

2017-11-29 08_38_44-junitoutput

Stacktrace:

org.spockframework.util.InternalSpockError: Failed to instantiate spec 'HelloSpockSpecX2'
	at org.spockframework.runtime.BaseSpecRunner.createSpecInstance(BaseSpecRunner.java:113)
	at org.spockframework.runtime.BaseSpecRunner.run(BaseSpecRunner.java:65)
	at org.spockframework.runtime.Sputnik.run(Sputnik.java:63)
	at org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:86)
	at org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38)
	at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:459)
	at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:678)
	at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:382)
	at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:192)
Caused by: java.lang.ExceptionInInitializerError
	at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
	at sun.reflect.NativeConstructorAccessorImpl.newInstance(Unknown Source)
	at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(Unknown Source)
	at java.lang.reflect.Constructor.newInstance(Unknown Source)
	at java.lang.Class.newInstance(Unknown Source)
	at org.spockframework.runtime.BaseSpecRunner.createSpecInstance(BaseSpecRunner.java:107)
	... 8 more
Caused by: java.lang.RuntimeException: beep
	at vi.ota.integration.elastic.MyObject.<init>(MyObject.java:6)
	at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
	at sun.reflect.NativeConstructorAccessorImpl.newInstance(Unknown Source)
	at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(Unknown Source)
	at java.lang.reflect.Constructor.newInstance(Unknown Source)
	at org.codehaus.groovy.reflection.CachedConstructor.invoke(CachedConstructor.java:83)
	at org.codehaus.groovy.runtime.callsite.ConstructorSite$ConstructorSiteNoUnwrapNoCoerce.callConstructor(ConstructorSite.java:105)
	at org.codehaus.groovy.runtime.callsite.CallSiteArray.defaultCallConstructor(CallSiteArray.java:60)
	at org.codehaus.groovy.runtime.callsite.AbstractCallSite.callConstructor(AbstractCallSite.java:235)
	at org.codehaus.groovy.runtime.callsite.AbstractCallSite.callConstructor(AbstractCallSite.java:239)
	at vi.ota.integration.elastic.x.HelloSpockSpecX2.<clinit>(HelloSpockSpecX2.groovy:13)
	... 14 more

Example:

package x

import org.junit.ClassRule
import org.junit.Rule
import spock.lang.Specification
import x.MyObject
import spock.lang.*

class HelloSpockSpecX2 extends Specification {
	
	public static MyObject docker = new MyObject();
	
  def "Test"() {
	expect:
	name.size() == length

	where:
	name     | length
	"Spock"  | 5
	"Kirk"   | 4
	"Scotty" | 6
  }
}

package x;

public class MyObject {

	public MyObject() {
		throw new RuntimeException("beep");
	}
}

Additional Environment information

Version of your build tool(if used), Java, Groovy, IDE, OS etc
Java 8, Groovy 2.4.9, Eclipse Ogygen 4.7.0, Windows, Spock 1.1

@leonard84

This comment has been minimized.

Show comment
Hide comment
@leonard84

leonard84 Jan 18, 2018

Member

There is actually no test running that can be reported as failure since it crashes before spock reaches it. Due to the internal structure that is unlikely to change in Spock 1.x but might be tackled in Spock 2.x which will be based on the new JUnit Plattform.

Member

leonard84 commented Jan 18, 2018

There is actually no test running that can be reported as failure since it crashes before spock reaches it. Due to the internal structure that is unlikely to change in Spock 1.x but might be tackled in Spock 2.x which will be based on the new JUnit Plattform.

@leonard84 leonard84 added the not a bug label Jul 7, 2018

@leonard84 leonard84 closed this Jul 7, 2018

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment