Grails (JUnit) test suite - testing

Do JUnit test suites work in Grails?
I am writing a Groovy/Grails(2.1.2) project using IntelliJ.
Is it possible to run Spock tests as a JUnit test suite? I have tried:
package com.foo
import com.foo.functional.SampleFunctionalSpec
import org.junit.experimental.categories.Categories
import org.junit.runner.RunWith
import org.junit.runners.Suite
#RunWith(Categories.class)
#Categories.IncludeCategory(Category1.class)
#Suite.SuiteClasses( {SampleFunctionalSpec.class} )
class SampleTestSuite {
}
and
package com.foo.functional
import com.foo.*
import org.junit.experimental.categories.Category;
#Category(Category1.class)
class SampleFunctionalSpec extends BloomGebSpecCase {
def "Sample test 1 with Category1"() {
given:
when:
println "when"
then:
println "Sample test 1 with Category1"
}
}
and
package com.foo
interface Category1 { }
and I get "Unable to attach test reporter to test framework..." when I run grails test-app functional SampleTestSuite from within IntelliJ.
EDIT: Also, just running a test suite with no categories gives same "Unattached" problem:
#RunWith(Suite.class)
#Suite.SuiteClasses( SampleFunctionalSpec.class )
class SampleTestSuite { }

Related

Cucumber+Appium - 'CukesRunner' class is not running and displays exit code 0 in console

I have setup a Gradle project to automate an Android application using Cucumber and Appium with Java. I also wanted to use POM to capture the elements page-wise. The project structure looks like:
I wants to add Extent Report to get testcase execution status. Now when i am running CukesRunner file:
package runners;
import io.cucumber.junit.Cucumber;
import io.cucumber.junit.CucumberOptions;
import org.junit.runner.RunWith;
#RunWith(Cucumber.class)
#CucumberOptions(
plugin = {
"json:target/cucumber.json",
"html:target/default-html-reports",
"rerun:target/rerun.txt"
},
features = {"src//test//resources//Features"},
glue = {"stepdefinition"},
dryRun = false,
tags = "#paybackTest"
)
public class CukesRunner {
}
It displays the exit code 0 error with some unknown error:
My appium server is running on 127.0.0.1:4723 and also an Android device connected through USB (i cross-checked it with 'adb devices').

Junit 5 suite is not running tests in command line

I am trying to run TestSuite using Junit 5. Individual file run fine. But TestSuite is not running when executed from command line. I am using junit-platform-console-standalone-1.6.0.jar to run tests.
My Test classes are:
package demo;
import org.junit.jupiter.api.AfterAll;
import org.junit.jupiter.api.Test;
public class TestDemoClass1 {
#Test
public void test1() throws Exception {
System.out.println("Test 1 from DemoClass 1");
}
#Test
public void test2() throws Exception {
System.out.println("Test2 from DemoClass 1");
}
}
My Suite calss is:
package demo;
import org.junit.platform.suite.api.SelectClasses;
import org.junit.platform.suite.api.Suite;
#Suite
#SelectClasses({ TestDemoClass1.class })
public class TestSuite {
}
The command I am usign to run from command lines:
java -jar target/junit-platform-console-standalone-1.6.0.jar -cp .;target/test-classes/ -c demo.TestSuite
This is resolved ":https://github.com/junit-team/junit5/issues/2813.
The issue was not adding set of jars while runnign command needed for console launcher.
Additional info in above GitHub issue link but in summary you need to add following jars to classpath:
junit-platform-console-standalone-1.8.2.jar;
junit-platform-suite-api-1.8.2.jar;
junit-platform-suite-commons-1.8.2.jar;
junit-platform-suite-engine-1.8.2.jar; \

Getting org.junit.runner.RunWith is not an annotation type with Cucumber

I'm trying to set-up a Selenium + Cucumber project in Java (I'm a beginner with Java) in Intellij. This is my class that uses the Cucumber JUnit runner:
package runtest;
import cucumber.api.CucumberOptions;
import cucumber.api.junit.Cucumber;
import org.junit.runner.RunWith;
#RunWith(Cucumber.class)
#CucumberOptions (
features = "C:\\Users\\my-feature.feature",
)
public class RunTest {
}
I'm getting these errors:
Error:(8, 1) java: annotation #org.junit.runner.RunWith is missing default values for elements annotationType,<init>
Error:(8, 2) java: org.junit.runner.RunWith is not an annotation type
I don't know how to resolve this or what is happening. Please help.
I had multiple RunWith classes in my project path. After pruning the project tree, it works as expected.
You don't have to provide the absolute path of the feature file if you opt to place it within your project space. The name of the feature file folder would be enough.
As an example, if you are having the following structure:
Package: Q43966680
Class: Runner
Feature File Folder: q43966680
Snapshot:
As per your usecase within #CucumberOptions you just need to mention:
#RunWith(Cucumber.class)
#Cucumber.Options (features="q43966680")
public class RunTest {
}

Failed to instantiate class in selenium-cucumber framework

I am using cucumber 3.0.2.My testrunner code is given below.
package futurerx_testrunner_pkg;
import org.junit.runner.RunWith;
import cucumber.api.junit.Cucumber;
import cucumber.api.CucumberOptions;
#RunWith(Cucumber.class)
#CucumberOptions(features="features/login.feature",glue= {"stepdefinition"})
public class testrunner {
}
I have created 2 packages in src(futurerx_testrunner_pkg and stepdefinition).I have testrunner.java in futurerx_testrunner_pkg package and Basedefinition.java in stepdefinition package.
But when i am running the code,it gives an error "Failed to instantiate class stepdefinition.Basedefinition at cucumber.runtime.java.DefaultJavaObjectFactory.cacheNewInstance(DefaultJavaObjectFactory.java:47) at cucumber.runtime.java.DefaultJavaObjectFactory.getInstance(DefaultJavaObjectFactory.java:33) at cucumber.runtime.java.JavaStepDefinition.execute(JavaStepDefinition.java:48)".
I am new to this cucumber-selenium framework and not understanding where i am going wrong.Thanks in Advance.

Unable to resolve class org.gradle.util.TestUtil in Gradle

This error means that class TestUtil is not on the classpath and the compiler can not find it. I came across such error hundred times before and there was missing Jar or wrong written class names, but now I just don't know what is wrong.
In my buildSrc dir I have custom Task and I made test for it:
package com.example.core.tasks;
import spock.lang.Specification
import org.gradle.api.Project
import org.gradle.util.TestUtil
public class GetInfoTaskTest extends Specification {
def "check files"(){
given:
def project = TestUtil.createRootProject()
when:
GetInfoTask getInfo = project.tasks.create("getInfo", GetInfoTask)
then:
getInfo instanceof GetInfoTask.class
}
}
In the build script in the buildSrc dir:
dependencies {
compile localGroovy()
testCompile 'org.spockframework:spock-core:0.7-groovy-1.8'
testCompile gradleApi()
}
Error:
GetInfoTaskTest.groovy: 4: unable to resolve class org.gradle.util.TestUtil
# line 3, column 1.
import org.gradle.util.TestUtil
^
I checked that this TestUtil is not internal. I still don't know why gradle can not find it.
TestUtil is an internal class. You can't use it in your own code.