Is there any way to run an individual test method in groovy? - groovy

I'd like to run an individual test method instead of the entire test class in Groovy on the cli - is this possible?
So instead of all the test methods in MyTestClass, I'd like to run just the testArbitrary method in MyTestClass.
Any help appreciated.

In Intellij Idea you could create run configuration, that will start single test method. Command will be copied to output panel and will look like so
com.intellij.rt.execution.junit.JUnitStarter -ideVersion5 -junit3 package.TestClass,testMethod
Like this, you can create your custom JUnitStarter class as described here https://stackoverflow.com/a/9288513/1601606
Natively, there is no such class, but it's pretty simple to create it.

Related

In a Kotlin multi-platform (or JS) project, (how) can one pass custom command line arguments to Node.js?

I'm working on a Kotlin multi-platform project, and I need my JS tests to run on Node.js but with custom command line arguments (specifically I need node to run with the --expose-gc flag, because some tests need to trigger garbage collection).
Looking at the documentation for the Gradle Kotlin JS DSL I didn't find any mention of how to do that; does anyone know whether it's at all possible and how?
Unfortunately can not answer your question directly, but there is some suggestion to help you with reverse engineering.
Let's start from some example. We have Gradle tasks to run our project using webpack's dev server such as browserDevelopmentRun, browserProductionRun (not sure if multi-platform projects have it, but JS projects do). We can add:
println(tasks.named("browserProductionRun").get().javaClass)
to build.gradle.kts to find out the exact class used for this task. When we sync Gradle, it outputs:
org.jetbrains.kotlin.gradle.targets.js.webpack.KotlinWebpack_Decorated
Now we know the exact class of this task so we can investigate its API. The auto completion or navigating inside of the KotlinWebpack class helps us to find out that it has a helpful nodeArgs property to configure NodeJS arguments for it, so we can set them, for example:
tasks.named("browserProductionRun", org.jetbrains.kotlin.gradle.targets.js.webpack.KotlinWebpack::class).get().nodeArgs.add("--trace-deprecation")
Getting back to your question.
In your case I guess you need to investigate the browserTest task. Let's get some info about it by adding:
println(tasks.named("browserTest").get().javaClass)
to build.gradle.kts - a-ha - it seems to be of the org.jetbrains.kotlin.gradle.targets.js.testing.KotlinJsTest_Decorated type. Let's check what's inside. Open KotlinJsTest.kt somehow - for example by typing its name into the window being opened by CMD + Shift + O (make sure to select "All Places" here) or just by typing its name somewhere in build.gradle.kts and navigating inside it.
The only interesting thing I see inside this open class is the following block:
override fun createTestExecutionSpec(): TCServiceMessagesTestExecutionSpec {
val forkOptions = DefaultProcessForkOptions(fileResolver)
forkOptions.workingDir = npmProject.dir
forkOptions.executable = nodeJs.requireConfigured().nodeExecutable
val nodeJsArgs = mutableListOf<String>()
return testFramework!!.createTestExecutionSpec(
task = this,
forkOptions = forkOptions,
nodeJsArgs = nodeJsArgs,
debug = debug
)
}
So maybe it can work out to create your own extension of this class, override its createTestExecutionSpec method and provide nodeJsArgs as you need inside it. After that you'll be needing to declare another Gradle task to launch tests inside build.gradle.kts which will use this new extended class.

Store custom Groovy function in JMeter UI

Been struggling with this a lot lately: How do I store a custom Groovy script with imports etc in the JMeter UI so I can reuse it later?
I don't want to alter JMeter startup property files in any way
I want to be able to call this Groovy 20+ times within the JMX with different parameters
From the JMeter doc:
Once the script is working properly, it can be stored as a variable on
the Test Plan. The script variable can then be used to create the
function call.
The groovy (compatible with Beanshell) is 62 lines and includes imports of custom JAR files. If I could store this as a var callable with __groovy(param) that would be great, I don't see how to do that from the docs. Setting up 20 JSR223s is incredibly clunky but I am coming up with workarounds if there is no JMeter way to do this.
References:
https://jmeter.apache.org/usermanual/best-practices.html#developing_scripts
Depending on what you're trying to achieve:
There is a possibility to specify a path to the file with your code in any of JSR223 Test Elements so you won't have to copy and paste it multiple times into "Script" area so in case of changes you will need to amend it in one place only:
There is groovy.utilities property where you can specify the path to your .groovy file containing the logic callable from the __groovy() function, it defaults to bin/utility.groovy
You can compile your code to .jar file and store it under JMeter Classpath, this way you will be able to call your functions from any place. See How to Reuse Your JMeter Code with JAR Files and Save Time article for example implementation/usage details

Sub-Functions In Python?

I'm creating a project which the user can call functions from my script. My goal is to try and make the syntax very clean. I would like to add a "sub function" for my script, to make the user's code more compact.
I'm already using a class for the script, so that wouldn't be an option.
Currently I've got this:
myDatabase.fetch("notes")
How can I make my syntax look more like this?
myDatabase.fetch("notes").where("theseNotes")
Here is another example:
firstFunction().secondFunction()

confusion in context variable and Context Class in soap Ui

context,testRunner variables(built-in) in SoapUI are objects/instances of which classes in soapui api.
I was under impression that context variable is an instance of
com.eviware.soapui.impl.wadl.inference.schema.Context
but in the Context class i could not find exapnd method which we use regualrly as shown below
context.expand('${#level#request}')
Please some body clarify...if both are difference where can i find list of all methods of context variable
Thanks
The class of the context variable could be different depending on context.
The best way to get the class name to print it out:
log.info( context.getClass() )
If we talk about groovy script test step then context should be
com.eviware.soapui.impl.wsdl.panels.support.MockTestRunContext if you run just your script without running the whole test case.
com.eviware.soapui.impl.wsdl.testcase.WsdlTestRunContext if you run the whole or part of the test case including your script.
probably it could be other for different soapui project types..
So, what is the context of your groovy script?
Btw, how did you get com.eviware.soapui.impl.wadl.inference.schema.Context ?
SoapUI initializes certain variables in certain level.
Here are the list of variables available at different level.
Project Setup Script
context
project
runner
log
Similarly, below variables available at Test Suite Setup Script
context
testSuite
runner
log
And also certain variables available in Test Case Setup Script.
The same is with TearDown Scripts as well.
However, If I understand right, you were referring to Groovy Script test step.
And the following variables are available there are:
testRunner
context
log
To be more precise, context.expand() is used to read certain property values either from test case, suite or project.
In order to read test case level property, CASE_PROPERTY
User one of the two:
context.expand('${#TestCase#CASE_PROPERTY}')
context.testCase.getPropertyValue('CASE_PROPERTY')
In order to read test suite level property, SUITE_PROPERTY
User one of the two:
context.expand('${#TestSuite#SUITE_PROPERTY}')
context.testCase.testSuite.getPropertyValue('SUITE_PROPERTY')
In order to read test project level property, PROJECT_PROPERTY
User one of the two:
context.expand('${#TestSuite#SUITE_PROPERTY}')
context.testCase.testSuite.getPropertyValue('SUITE_PROPERTY')

Using GroovyScript in SoapUI to access and lock an external file

I have a set of 60 testcases in a project in SoapUI that I want to run concurrently. Each testcase needs to use a value to work. The values are stored in an external file (spreadsheet or textfile). Each testcase needs to get a value from this file and use it. However when I run the testsuite, multiple tests are picking up the same value however only one value can be used for a test (same value cannot be used in more than 1 test at the same time). I would like the external file to be accessed by one testcase at a time in soapUI. Does this involve locking or some sort of queueing system or what groovyscript could I use? thanks
I can't figure out how to get this to work with your external file, but I can think of another way only using SoapUI. Here's my suggestion for a solution:
Create a new TestCase containing only a DataGen TestStep.
Configure it so that it generates the numbers you want.
Change its mode to "READ", so that it will generate a new value every time the test step is run.
Now, wherever you want one of these values, instead of accessing your external file, add a Run TestCase TestStep to run your new DataGen test case, and make sure to return the generated number as a property. Use it where you need the generated number.
As I'm typing this, I just realized this only works with the pro version of SoapUI. If you don't have a license you can get a trial from the website.

Resources