Run an arquillian test using "Run as Junit" from JBoss Developer studio using gradle
superand May 21, 2014 4:27 AMHello and thank you for your time in reading this question.
I am trying to run a test class from JBoss Developer studio using the "Run as Junit" run configuration. The test project runs as it is supposed to from command line using gradle and it also worrks from the IDE using the gradle plugin. The problem is that when the test class is run using "Run as JUnit" I get the following exception:
java.lang.RuntimeException: Could not create new instance of class org.jboss.arquillian.test.impl.EventTestRunnerAdaptor at org.jboss.arquillian.test.spi.SecurityActions.newInstance(SecurityActions.java:160) at org.jboss.arquillian.test.spi.SecurityActions.newInstance(SecurityActions.java:111) at org.jboss.arquillian.test.spi.SecurityActions.newInstance(SecurityActions.java:97) at org.jboss.arquillian.test.spi.TestRunnerAdaptorBuilder.build(TestRunnerAdaptorBuilder.java:52) at org.jboss.arquillian.junit.Arquillian.run(Arquillian.java:93) at org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:50) at org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38) at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:467) at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:683) at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:390) at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:197) Caused by: java.lang.reflect.InvocationTargetException at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method) at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:57) at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45) at java.lang.reflect.Constructor.newInstance(Constructor.java:526) at org.jboss.arquillian.test.spi.SecurityActions.newInstance(SecurityActions.java:156) ... 10 more Caused by: org.jboss.arquillian.container.impl.ContainerCreationException: Could not create Container jbossAS7Remote at org.jboss.arquillian.container.impl.LocalContainerRegistry.create(LocalContainerRegistry.java:85) at org.jboss.arquillian.container.impl.client.container.ContainerRegistryCreator.createRegistry(ContainerRegistryCreator.java:76) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) at java.lang.reflect.Method.invoke(Method.java:606) at org.jboss.arquillian.core.impl.ObserverImpl.invoke(ObserverImpl.java:94) at org.jboss.arquillian.core.impl.EventContextImpl.invokeObservers(EventContextImpl.java:99) at org.jboss.arquillian.core.impl.EventContextImpl.proceed(EventContextImpl.java:81) at org.jboss.arquillian.core.impl.ManagerImpl.fire(ManagerImpl.java:135) at org.jboss.arquillian.core.impl.ManagerImpl.fire(ManagerImpl.java:115) at org.jboss.arquillian.core.impl.ManagerImpl.bindAndFire(ManagerImpl.java:236) at org.jboss.arquillian.core.impl.InstanceImpl.set(InstanceImpl.java:74) at org.jboss.arquillian.config.impl.extension.ConfigurationRegistrar.loadConfiguration(ConfigurationRegistrar.java:60) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) at java.lang.reflect.Method.invoke(Method.java:606) at org.jboss.arquillian.core.impl.ObserverImpl.invoke(ObserverImpl.java:94) at org.jboss.arquillian.core.impl.EventContextImpl.invokeObservers(EventContextImpl.java:99) at org.jboss.arquillian.core.impl.EventContextImpl.proceed(EventContextImpl.java:81) at org.jboss.arquillian.core.impl.ManagerImpl.fire(ManagerImpl.java:135) at org.jboss.arquillian.core.impl.ManagerImpl.fire(ManagerImpl.java:115) at org.jboss.arquillian.core.impl.ManagerImpl.start(ManagerImpl.java:261) at org.jboss.arquillian.test.impl.EventTestRunnerAdaptor.<init>(EventTestRunnerAdaptor.java:56) ... 15 more Caused by: java.lang.IllegalArgumentException: DeployableContainer must be specified at org.jboss.arquillian.core.spi.Validate.notNull(Validate.java:44) at org.jboss.arquillian.container.impl.ContainerImpl.<init>(ContainerImpl.java:71) at org.jboss.arquillian.container.impl.LocalContainerRegistry.create(LocalContainerRegistry.java:76) ... 39 more
It seems that when I run it like this it cannot find the container for jboss 7 remote.
My gradle build script looks like this:
apply plugin: JavaPlugin apply plugin: 'eclipse' ext.libraryVersions = [ junit: '4.8.1', arquillian: '1.1.1.Final', jbossJavaeeSpec: '1.0.0.Final', weld: '1.1.1.Final', slf4j: '1.5.10', log4j: '1.2.14', jbossAS6: '6.0.0.Final', glassfish: '4.0-b72', cdi: '1.0-SP4', hamcrest: '1.2', jbossAS7: '7.1.1.Final', shrinkwrapDesc: '2.0.0-alpha-3' ] repositories { mavenCentral() // enable if you want to use snapshots published locally //mavenRepo urls: 'file://' + System.getProperty('user.home') + '/.m2/repository' maven{ url 'http://repository.jboss.org/nexus/content/groups/public'} maven{ url 'http://repository.jboss.org/nexus/content/repositories/deprecated'} } sourceSets { test { java { srcDir 'src/java' } resources { srcDir 'src/test/resources-jbossas-managed' } } } configurations { compileOnly weldEmbeddedTestRuntime { extendsFrom testRuntime } jbossAS6RemoteTestRuntime { extendsFrom testRuntime, compileOnly } jbossAS7ManagedTestRuntime { extendsFrom testRuntime, compileOnly } jbossAS7RemoteTestRuntime { extendsFrom testRuntime, compileOnly } glassfishEmbeddedTestRuntime { extendsFrom testRuntime } } dependencies { compile 'org.jboss.spec:jboss-javaee-6.0:1.0.0.Final' testCompile group: 'junit', name: 'junit', version: libraryVersions.junit testCompile group: 'org.hamcrest', name: 'hamcrest-core', version: libraryVersions.hamcrest testCompile group: 'org.jboss.arquillian.junit', name: 'arquillian-junit-container', version: libraryVersions.arquillian testCompile group: 'org.jboss.shrinkwrap.descriptors', name: 'shrinkwrap-descriptors-api-javaee', version: libraryVersions.shrinkwrapDesc testRuntime group: 'org.jboss.shrinkwrap.descriptors', name: 'shrinkwrap-descriptors-impl-javaee', version: libraryVersions.shrinkwrapDesc weldEmbeddedTestRuntime group: 'org.jboss.arquillian.container', name: 'arquillian-weld-ee-embedded-1.1', version: '1.0.0.CR7' weldEmbeddedTestRuntime group: 'org.jboss.spec', name: 'jboss-javaee-6.0', version: libraryVersions.jbossJavaeeSpec weldEmbeddedTestRuntime group: 'org.jboss.weld', name: 'weld-core', version: libraryVersions.weld weldEmbeddedTestRuntime group: 'org.slf4j', name: 'slf4j-log4j12', version: libraryVersions.slf4j weldEmbeddedTestRuntime group: 'log4j', name: 'log4j', version: libraryVersions.log4j jbossAS6RemoteTestRuntime group: 'org.jboss.arquillian.container', name: 'arquillian-jbossas-remote-6', version: libraryVersions.arquillian jbossAS6RemoteTestRuntime group: 'org.jboss.spec', name: 'jboss-javaee-6.0', version: libraryVersions.jbossJavaeeSpec jbossAS6RemoteTestRuntime group: 'org.jboss.jbossas', name: 'jboss-as-profileservice-client', version: libraryVersions.jbossAS6 jbossAS7ManagedTestRuntime group: 'org.jboss.as', name: 'jboss-as-arquillian-container-managed', version: libraryVersions.jbossAS7 jbossAS7ManagedTestRuntime group: 'org.jboss.spec', name: 'jboss-javaee-6.0', version: libraryVersions.jbossJavaeeSpec jbossAS7RemoteTestRuntime group: 'org.jboss.as', name: 'jboss-as-arquillian-container-remote', version: libraryVersions.jbossAS7 jbossAS7RemoteTestRuntime group: 'org.jboss.spec', name: 'jboss-javaee-6.0', version: libraryVersions.jbossJavaeeSpec glassfishEmbeddedTestRuntime group: 'org.jboss.arquillian.container', name: 'arquillian-glassfish-embedded-3.1', version: '1.0.0.CR4' glassfishEmbeddedTestRuntime group: 'org.glassfish.main.extras', name: 'glassfish-embedded-all', version: libraryVersions.glassfish } sourceSets { main { compileClasspath = configurations.compile + configurations.compileOnly } test { compileClasspath = compileClasspath + configurations.compileOnly } } task weldEmbeddedTest(type: Test) task jbossAS6RemoteTest(type: Test) task jbossAS7ManagedTest(type: Test) task jbossAS7RemoteTest(type: Test) { systemProperty "arquillian.launch", "jbossAS7Remote" } task glassfishEmbeddedTest(type: Test) tasks.withType(Test).matching({ t-> t.name.endsWith('Test') } as Spec).each { t -> t.classpath = project.configurations.getByName(t.name + 'Runtime') + project.sourceSets.main.output + project.sourceSets.test.output if (t.name.startsWith('jbossas')) { t.classpath += files('src/test/resources-jbossas') } } test { dependsOn { weldEmbeddedTest } } task generateWrapper(type: Wrapper) { gradleVersion = '1.7' }
From the arquillian guide, the solution to use the "Run as JUnit" from IDE involves activating a maven profile (http://arquillian.org/guides/getting_started/#run_the_arquillian_test) but i am using gradle and I do not have that option.
If you need any other information regarding my setup I will try to provide it as quickly as i can.
Thank you.