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

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.

Related

How to parameterise the cucumber options tags from jenkins in karate

I have below java class which runs with cucumberOptions
#CucumberOptions(tags = {"#userManagement"})
public class IC_API_Tests_Runner {
runner code here
}
From jenkins I am passing below command ti run the tests
clean test "-Dkarate.env=$WhereToRun" "-Dbvt.tags=#userManagement"
I am able to fetch the value of 'bvt.tags' using below command
bvtTags = karate.properties['bvt.tags'];
Now I need to pass the 'bvtTags' value to the CucumberOptions.
I tried
#CucumberOptions(tags = {"bvtTags"})
public class IC_API_Tests_Runner {
runner code here
}
But 'bvtTags' value is not substituted in the CucumberOptions. But I am able to print the value of 'bvtTags' with print statement in karate code.
Any help will be great help
No you can't do dynamic changing of the #CucumberOptions like that.
Use the API for dynamically choosing tests, see this example: DemoTestSelected.java.
Then do something like this (please change for your environment):
String tags = System.getProperty("bvt.tags");
List<String> tags = Arrays.asList(tags);
EDIT: actually you don't need to do any of this. (I guess that you will never read the docs :)
Please refer: https://github.com/intuit/karate#command-line
-Dkarate.options="--tags #userManagement"

Run an individual test parameter in junit 5

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:

How to run an specific test case in the selected environment in SoapUI

I have multiple Environment and a lot of test cases, but not all test cases are needed to be run in all environment. Is there a way to run only an specific test cases from a test suite based on the selected Environment.
For Example
If I select Environment1, it will run the following test cases
TC0001
TC0002
TC0003
TC0004
TC0005
If I select Environment2, it will run only the following test cases
TC0001
TC0003
TC0005
There can be different solution to achieve this since you have multiple environments i.e., pro software being used.
I would achieve the solution using Test Suite's Setup Script:
Create Test Suite level custom property. Use the same name as your environment name. For instance, DEV is the environment defined, use the same as test suite property name and provide the list of values separated by comma as value for that property, say TC1, TC2 etc.,
Similarly defined other environments and its values as well.
Copy the below script in Setup Script for the test suite and execute the script which enables or disables the test cases according to the environment and property value
Test Suite's Setup Script
/**
* This is soapui's Setup Script
* which enables / disables required
* test cases based on the user list
* for that specific environment
**/
def disableTestCase(testCaze) {
testCaze.disabled = true
}
def enableTestCase(testCaze) {
testCaze.disabled = false
}
def getEnvironmentSpecificList(def testSuite) {
def currentEnv = testSuite.project.activeEnvironment.NAME
def enableList = testSuite.getPropertyValue(currentEnv).split(',').collect { it.trim()}
log.info "List of test for enable: ${enableList}"
enableList
}
def userList = getEnvironmentSpecificList(testSuite)
testSuite.testCaseList.each { kase ->
if (userList.contains(kase.name)) {
enableTestCase(kase)
} else {
disableTestCase(kase)
}
}
Other way to achieve this is using Event feature of ReadyAPI, you may use TestRunListener.beforeRun() and filter the test case whether to execute or ignore.
EDIT:
If you are using ReadyAPI, then you can the new feature called tag the test cases. A test case can be tagged with multiple values and you can execute tests using specific tags. In this case, you may not needed to have the setup script as that is for the open source edition. Refer documentation for more details.
This solution is only specific to Pro software and Open Source edition does have this tag feature.

How to write a custom Failure message for the Failed Step in Cucumber-java in extentReports

I want to write custom failure message in my Cucumber ExtentReports.
Tool using :
Cucumber
Java
Selenium
JUnit
ExtentReports
What's happening now:
I have a cucumber scenario.
Given something
When I do something
Then this step fails
The failed step Fails with:
Assert.assertTrue("CUSTOM_FAIL_MSG", some_condition);
In the ExtentReport, I see the
What I want to achieve:
What I have researched so far:
There is a scenario.write("") function but this creates a new info log into the report(But I am looking for CustomFailure message rather than a new log entry)
scenario.stepResults has the String which is displayed in the report. However, I could not find a way to set some value in the same.
Any ideas on this?
Have you tried using the create label markup?
Here is how to do it for the FAILED test:
test.log(Status.FAIL, MarkupHelper.createLabel(result.getName()+" Your MSG here!", ExtentColor.RED));
and the PASSED test:
test.log(Status.PASS, MarkupHelper.createLabel(result.getName()+" Test Case PASSED", ExtentColor.GREEN));
You can easily manipulate the string part (var interpolation?) according to your need.
Does this help?
try to replace the JUnit assertion library with the testNG library...also using cucumber you can see the failed step...why do you want to change this "narrative" log?...or if you want a better report try to use a 3rd party library

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