Run an individual test parameter in junit 5 - junit5

Lets say I have a parameterized test like this:
#ParameterizedTest
#ValueSource(strings = {"a", "B", "r"})
void test1(String val) {
assertNotNull(val);
}
What I'd like to do is just run the test for one value. Is there a way to do it? I know how to run an individual test, but if there's a notation to run just the one parameter, that would be of help. Looking to run it through Maven.

If you use Eclipse, you can specify the "uniqueId" parameter as a test run parameter.
You can extract the id (which is a very complicated string) as follows.
Run the test as usual, so Eclipse will show each single run in the JUnit panel as a tree.
Select a single run and execute it in debug mode, place a breakpoint whereever you want.
Click on the Properties menu in the Debug perspective:
Copy the uniqueId parameter from the Command Line window:
And add it as a command line parameter in your JUnit Run configuration:

Related

how to run only one test in scalatest/playspec

My spec file has several tests
"HomeController index page" should {
"have title Welcome " in {
....
}
"Home controller " should {
"render homepage with csrfToken" in {
...
}
To run the tests in IntelliJ, I right-click on the spec file and select run. But this runs all the tests. Is there a way to select tests and run only the selected ones?
You should be able to run individual tests by placing the cursor inside the test method and pressing Ctrl+Shift+F10 or by creating the ScalaTest run/debug configuration where you can specify the test name to run.
See also Test scopes in Scala section in the documentation:

NUnit - Running specific test case using testcase attribute through command line

I want to run the below test case through nunit console using command line.`
class ListCities : Test.HelperClasses.Testbase
{
[TestCase(Category="smoke",TestName = "TC1", Description = "dessciption")]
public void SearchCity()
{
}
}`
I tried the command --test=Test.HelperClasses.Testbase.ListCities.TC1.
But i want to execute the test using only testname(TC1) attribute and not along with the namespace(Test.HelperClasses.Testbase) and class name(ListCities).
Below is the python code to execute the test case using nunit console
os.system("Call "+NunitPath+" "+dllPath+" --
test=Test.HelperClasses.Testbase.ListCities.TC1 --result="+resultPath)
Thanks in advance
The TestName property of TestCaseAttribute only sets the name of the test. The --test option of the console runner uses the full name of the test. The alternative you tried is the right way to specify this test case - that's how NUnit works.
If you want to have a more succinct syntax, read the documentation for the --where option. It would allow you to do something like --where test=~TC1.

Jenkins' EnvInject Plugin does not persist values

I have a build that uses EnvInject Plugin to set an environmental value.
A different job needs to scan last good Jenkins build of that job and get the value of that environmental variable.
This all works well, except sometimes the variable will disappear from build history. It seems that after some time passes, when I look at the 'Environment variables' section in build history, the injected value simply disappears.
How can I make this persist? Is this a bug, or part of the design?
If it make any difference, the value of the injected variable is +1500 chars and in the following format: 'component1=1.1.2;component2=1.1.3,component3=4.1.2,component4=1.1.1,component4=1.3.2,component4=1.1.4'
Looks like EnvInject and/or JobDSL have a bug.
Steps to reproduce:
Set up a job that runs this JobDSL:
job('run_deploy_mock') {
steps {
environmentVariables {
env('deployedArtifacts', 'component1=1.0.0.2')
}
}
}
Run it and it will create a job called 'deploy_mock'
Run the 'deploy_mock' job. After build #1 is done, go to build details and check 'Environmental Variables' section for an entry called 'component1'
Run the JobDSL job again
Check 'Environmental Variables' section for 'deploy_mock' build #1. The 'component1' variable is now missing.
If I substitute the '=' for something else, it works as expected.
Created Jenkins Jira

how to debug a single testng test with parameters in intelliJ without using #Optional?

I have following test case that I want to debug in IntelliJ. I don't want to use #Optional("defaultValue") annotation because I want to debug the test with a real value that changes every time I debug. It is not handy to set default values every time I want to run tests.
#Test(parameters = { "param1"})
public void testExmaple(String param1){
//do something with param1
}
So, Is there are way to define the test data somewhere in intelliJ so that when I right-click and debug, it should pick the value i.e. param1 ? Or may be there is a testng plugin to do that ?
NOTE: I don't want to use command-line maven+surefire
Just configure the parameters part of the IntelliJ runner: https://www.jetbrains.com/help/idea/2016.1/run-debug-configuration-testng.html?origin=old_help#config

ScalaTest and IntelliJ - Running one Test at a time

I have a ScalaTest which extends the FlatSpec. I have many tests inside the test and I now want to have the possibility to run one test at a time. No matter what I do, I can't get IntelliJ to do it. In the Edit Configurations of the test, I can specify that it should run one test at a time by giving the name of the test. For example:
it should "test the sample multiple times" in new MyDataHelper {
...
}
where I gave the name as "test the sample multiple times", but it does not seem to take that and all I get to see is that it just prints Empty Test Suite. Any ideas how can this be done?
If using Gradle, go to Preferences > Build, Execution, Deployment > Build Tools > Gradle and in the Build and run > Run tests using: section, select IntelliJ IDEA if you haven't already.
An approach that works for me is to right-click (on Windows) within the definition of the test, and choose "Run MyTestClass..." -- or, equivalently, Ctrl-Shift-F10 with the cursor already inside the test. But it's a little delicate and your specific example may be causing your problem. Consider:
class MyTestClass extends FlatSpec with Matchers {
"bob" should "do something" in {
// ...
}
it should "do something else" in {
// ...
}
"fred" should "do something" in {
// ...
}
it should "do something else" in {
// ...
}
}
I can use the above approach to run any of the four tests individually. Your approach based on editing configurations works too. But if I delete the first test I can't run the second one individually -- the others are still fine. That's because a test that starts with it is intended to follow one that doesn't -- then the it is replaced with the appropriate string in the name of the test.
If you want to run the tests by setting up configurations, then the names of these four tests are:
bob should do something
bob should do something else
fred should do something
fred should do something else
Again, note the substitution for it -- there's no way to figure out the name of a test starting with it if it doesn't follow another test.
I'm using IntelliJ Idea 13.1.4 on Windows with Scala 2.10.4, Scala plugin 0.41.1, and ScalaTest 2.1.0. I wouldn't be surprised if this worked less well in earlier versions of Idea or the plugin.
I just realized that I'm able to run individual tests with IntelliJ 13.1.3 Community Edition. With the one that I had earlier 13.0.x, it was unfortunately not possible.