I would like to run all my test suites. I want to call the test suites in one test suit called Allrun.
Can I call test suites in another test suite. I am looking for something like this:
class Myfirst extends GebReportingSpec {
def myfunction(){
when:''
at mypage1
and:''
element1.text() == "mytext1"
}
}
class Mysecond extends GebReportingSpec {
def mysecondFunction() {
when:''
at mypage2
and:''
element2.text() == "mytext2"
}
}
class AlltestSuites extends GebReportingSpec {
Myfirst myfirst = new Myfirst ()
Mysecond mysecond = new Mysecond ()
def allrun(){
myfirst.myfunction()
mysecond.mysecondFunction()
}
}
How can i do this? Does anyone has an idea
You can create a AllRun.groovy file like below to run all class files in the specified order [Myfirst.class, Mysecond.class, etc].
package geb.groovy
import org.junit.runner.RunWith
import org.junit.runners.Suite
import geb.groovy.scripts.Myfirst
import geb.groovy.scripts.Mysecond
#RunWith(Suite.class)
#Suite.SuiteClasses([Myfirst.class, Mysecond.class])
class CustomJUnitSpecRunner {
}
And in build.gradle systemProperties System.properties, exclude the individual Myfirst.class, Mysecond.class files. So that they run only once through AllRun file.
include 'geb/groovy/AllRun/**'
exclude 'geb/groovy/scripts/**'
Groups of specs can be run using the command below, where package is a directory under src/test/groovy/specs:
mvn test -Dtest=specs.package.*
If you are relying on specs to be run in a particular order, I would reconsider your approach. If you require data in a certain state then make use of setup() and setupSpec() methods. Also consider running related tests within a single spec and run these in the order the are written by using the #Stepwise annotation.
#Stepwise
class MyStepWiseTest extends GebReportingSpec {
def myfunction(){
when:''
at mypage1
and:''
element1.text() == "mytext1"
}
def mysecondFunction() {
when:''
at mypage2
and:''
element2.text() == "mytext2"
}
}
Related
I have a TeamCity settings.kts code with configuration of build and I want to write a function inside settings.kts or in a file defined next to settings.kts and use the function inside kotlinScript step that is (KotlinScriptCustomBuildStep). How do I call the function (so that I don't need to write big logic inside kotlinScript.content?
//setting.kts
steps {
kotlinScript {
name = "Doing something"
//language=kotlin
content = """
import JiraReport
println(JiraReport().findLastMessage())
....
""".trimIndent()
}
//JiraReport class
import java.io.BufferedReader
import java.io.IOException
import java.io.InputStreamReader
class JiraReport {
fun findLastMessage(): String {
...
}
I am working on porting a JUnit4 based test framework that uses JUnitCore to launch unit tests with JUnit5 launcher, junit-vintage-engine and a LauncherDiscoveryRequest with ClassSelector.
It is working for all cases except #ParameterizedTest. Launcher is not honoring parameterized tests.
How do I get Launcher to honor JUnit4 parameterized tests?
I have tried adding testCompile("org.junit.jupiter:junit-jupiter-params:${junit_jupiter_version}")
package ...;
import org.junit.Assert;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.junit.runners.Parameterized;
import ...TestCategory;
import ...TestType;
import ...DataScramblingRegexTest;
#TestType(...TestCategory.UNIT)
#RunWith(Parameterized.class)
public class RegexGenTest {
private static final int LOOKAROUND_ATTEMPTS = 100;
#Parameterized.Parameter(0)
public String regex;
#Parameterized.Parameters(name = "{index}: RegexGenTest: {0}")
public static Iterable<String[]> data() {
return DataScramblingRegexTest.data();
}
#Test
public void testTransformAndGenerate() {
//even though Data Scramble Random Text doesn't transform every regex,
//even if we do, and run it through Generex, it should still work.
final String transformedRegex = RegexGen.transform(this.regex);
String randomStr = RegexGen.generate(transformedRegex);
if (RegexGen.containsLookArounds(this.regex)) {
for (int i = 0; i < LOOKAROUND_ATTEMPTS; i++) {
randomStr = RegexGen.generate(transformedRegex);
if (randomStr.matches(this.regex)) {
return;
}
}
Assert.fail("Lookaround failed");
}
Assert.assertTrue("generated string does not match regex: " + randomStr, randomStr.matches(this.regex));
}
}
build.gradle
compile("junit:junit:${junit_version}")
testCompile("org.junit.vintage:junit-vintage-engine:${junit_jupiter_version}")
testCompile("org.junit.jupiter:junit-jupiter-api:${junit_jupiter_version}")
testCompile("org.junit.jupiter:junit-jupiter-params:${junit_jupiter_version}")
testCompile("org.junit.jupiter:junit-jupiter-engine:${junit_jupiter_version}")
where
junit_version=4.12
junit_jupiter_version=5.4.2
Note the proprietary TestCategory.UNIT annotation, we use this in our test discovery code and create a Launcher and a LauncherdiscoveryRequest with ClassSelector.
I expect JUnit 4 parameters to be supported by JUnit5 launcher with junit-jupiter-vintage engine and it is not supported.
I have a test suite. I'd like to execute this entire test suite 1000 times. I have googled and looked everywhere and I can't seem to figure this out. Any help would be greatly appreciated!! If it would be easier to switch to testng, I will.
package com.bpms.tests;
import org.junit.runner.RunWith;
import org.junit.runners.Suite;
import org.junit.runners.Suite.SuiteClasses;
#RunWith(Suite.class)
#SuiteClasses({
InitiateBuyPlan.class,
AddItemsToBuyPlan.class,
ReviewBuyPlan.class,
ApproveBuyPlan.class,
ManageQuoteSolicitation.class,
StartQuote.class,
ReviewQuote.class,
RecordInterestInQuotes.class,
ReviewCountryBuyIn.class,
CompleteItemInfo.class,
ReviewItemInformation.class,
})
public class SuiteAllTests
{
}
You will have to build the test case programatically than via annotations
import org.junit.runners.AllTests;
import junit.framework.TestSuite;
import junit.framework.Test;
#RunWith(AllTests.class)
public final class SuiteAllTests {
public static TestSuite suite() {
TestSuite suite = new TestSuite();
for (int i= 0; i<1000; i++) {
suite.addTest(new JUnit4TestAdapter(XXX.class));
suite.addTest(new JUnit4TestAdapter(YYY.class));
}
return suite;
}
}
Just replace XXX and YYY with the classes you have in your annotations.
I have a set of Spec tests I am executing within a Grails Project.
I need to execute a certain set of Specs when I am on local, and another set of Spec when I run the pre-prod environment.
My current config is executing all my specs at the same time for both environements, which is something I want to avoid.
I have multiple environments, that I have configured in my GebConfig:
environments {
local {
baseUrl = "http://localhost:8090/myApp/login/auth"
}
pre-prod {
baseUrl = "https://preprod/myApp/login/auth"
}
}
You could use a spock config file.
Create annotations for the two types of tests - #Local and #PreProd, for example in Groovy:
import java.lang.annotation
#Retention(RetentionPolicy.RUNTIME)
#Target([ElementType.TYPE, ElementType.METHOD])
#Inherited
public #interface Local {}
Next step is to annotate your specs accordingly, for example:
#Local
class SpecificationThatRunsLocally extends GebSpec { ... }
Then create a SpockConfig.groovy file next to your GebConfig.groovy file with the following contents:
def gebEnv = System.getProperty("geb.env")
if (gebEnv) {
switch(gebEnv) {
case 'local':
runner { include Local }
break
case 'pre-prod':
runner { include PreProd }
break
}
}
EDIT: It looks like Grails is using it's own test runner which means SpockConfig.groovy is not taken into account when running specifications from Grails. If you need it to work under Grails then the you should use #IgnoreIf/#Require built-in Spock extension annotations.
First create a Closure class with the logic for when a given spec should be enabled. You could put the logic directly as a closure argument to the extension annotations but it can get annoying to copy that bit of code all over the place if you want to annotate a lot of specs.
class Local extends Closure<Boolean> {
public Local() { super(null) }
Boolean doCall() {
System.properties['geb.env'] == 'local'
}
}
class PreProd extends Closure<Boolean> {
public PreProd() { super(null) }
Boolean doCall() {
System.properties['geb.env'] == 'pre-prod'
}
}
And then annotate your specs:
#Requires(Local)
class SpecificationThatRunsLocally extends GebSpec { ... }
#Requires(PreProd)
class SpecificationThatRunsInPreProd extends GebSpec { ... }
Is there a way to run the tests within a spec in sequence?
#Stepwise
class TestSpec extends GebReportingSpec {
def 'A'(){
//
}
def 'B'(){
//
}
def 'C'(){
//
}
}
Is there a way I can force A to run before B and B to run before C?
Thanks,
Shravanthi
It should run in this order but with #Stepwise, you will keep the session between the features.