Add test cases to test set using Ruby Rally Rest API - rally

I'm trying to add test cases to a test set in Rally.
I have the test set object and the test case object.
I can REPLACE the entire test set list with THIS test case object and it works fine.
But I really need to ADD this test case to the list.
Any idea how I do this differently?
testset_object.update(:test_cases => test_case_object)

the :test_cases field should just be an array, so this should work:
tests = [test_case_object1, test_case_object2]
testset_object.update(:test_cases => tests)
Hope that helps

Related

Is there any API in JUnit 5 to test for included or excluded Tags?

I'd like to enable a test if a certain tag is "included", i.e. passed with option --include-tag of the ConsoleLauncher or useJUnitPlatform.includeTags property in Gradle. Is there any API to retrieve the value of this option in the context of test class or method?
I tried the script-based condition #EnabledIf like this:
#EnabledIf("'true' == systemProperty.get('itest.backendSystemPresent') || junitTags.contains('BackendSystemIT') == true")
But junitTags contains the #Tag annotations of the element in question, not the tags included at runtime.
Reading your question again, my answer is "No". You can't use junitTags to achieve your goals. And no, there's no such API at the moment. You would need something like:
#EnabledIf("'true' == evaluateTagExpression('BackendSystemIT') || ...)
Because you need to take care of tag expression here as well: https://junit.org/junit5/docs/current/user-guide/#running-tests-tag-expressions
But, tags are evaluated earlier in the process. Your condition will not get a chance to be executed when the test was already excluded by tag evaluation. So, I guess, you'll have to stick with the single system property switch to control the enabled state of the test method.
Btw. we are improving the tag expression language with any() and none() tokens, soon. https://github.com/junit-team/junit5/issues/1679
Possible solution:
Annotate your test with #Tag("BackendSystemIT")
Before running your tests, check for itest.backendSystemPresent system property and if it is set, pass a --include-tag "BackendSystemIT" to the test run.
Let Jupiter do the job of evaluating tag expressions
Is there any API to retrieve the value (of this option) of all tags that are attached directly or inherited in the context of test class or method?
Yes. Declare and use a org.junit.jupiter.api.TestInfo parameter in your test method.
#Test
#DisplayName("TEST 1")
#Tag("my-tag")
void test1(TestInfo testInfo) {
assertEquals("TEST 1", testInfo.getDisplayName());
assertTrue(testInfo.getTags().contains("my-tag"));
}
For details see https://junit.org/junit5/docs/current/user-guide/#writing-tests-dependency-injection
But junitTags contains the #Tag annotations of the element in question, not the tags included at runtime.
This is the expected behaviour -- the platform (here: console launcher) already applied the filter passed via --include-tag and other configuration parameters. In short: there's no need to manually check for tags in standard Jupiter tests. If there's problem with the built-in filtering, please create an issue here: https://github.com/junit-team/junit5/issues/new/choose

Phpunit yii: two fixtures to one table

In phpunit, with Yii, is possibile to create more fixtures for the same table?
I would like to have different fixtures folders to be used with different unit test, to avoid problems between the various test file.
You can set the fixture folder for each test by adding the following to your test classes:
protected function setUp()
{
$this->getFixtureManager()->basePath = 'path/to/fixtures';
parent::setUp();
}
With this, you can have your tests use whichever set of fixtures you want.
Make sure to call parent::setUp(), and to call it after setting the basePath property, as that is what actually loads the fixtures.
See also CDbFixtureManager.

SoapUI Free - Groovy Script in Property Value to Get TestSuite Property

I am using the free (non-PRO) SoapUI 5.0 and I have a list of properties in a Test Suite.
I then have a number of Test Steps, each one having the same name as a Test Suite property.
I'm trying to write Groovy script in a Test Step property to retrieve the value of the Test Suite property with the same name.
For example:
Test Suite has a property colour_red with the value 12345.
Within the Test Suite is a Test Case, with a Test Step also called colour_red.
Within the colour_red Test Step is a property "info".
I'm trying to get the property value for "info" to be the Test Suite
property colour_red value of 12345.
What I have so far in the "info" property value:
${=new GroovyShell().evaluate(testRunner.testCase.testSuite.project.getPropertyValue(context.getCurrentStep().getLabel()))}
I'm not sure if I need the new GroovyShell().evaluate bit, but without that it still doesn't work. I cannot tell exactly what is being picked up but it is not the value of the Test Suite property with the same name.
From what I can see the script should retrieve the current Test Step name (colour_red) and then look for a property called that in the Test Suite.
My reason for doing this is that I have data in the Test Suite property values which needs to be shared between numerous Test Cases (all with many Test Steps).
Without the PRO version I am struggling but I think with Groovy there should be a way to do this.
Any help appreciated, thanks.
I think researching property expansion will help you.
http://www.soapui.org/Scripting-Properties/property-expansion.html
To get you going...
You can easily reference property values using these dynamic references:
Put a reference like ${#TestSuite#colour_red} as the property value of "info".
Now the info property value is dynamicaly set to whatever the TestSuite's colour_red property value is.
I think this does what you want:
def myStep = context.currentStep.name
def myValue = context.expand( '${#Project#' + myStep + '}' )
testRunner.testCase.setPropertyValue("info", myValue)
I made it a little more verbose than it needs to be. I do not think that -Pro will help you, unless I misunderstood what you need.

Is it possible to run a single test using QUnit inside Karma?

Jasmine has iit() and ddescribe, and Mocha has it.only and describe.only, but I can't see any way to get QUnit to focus on running a single test.
The QUnit UI allows you to run a single test, but I can't see how to get this to work inside Karma, because it doesn't display the QUnit UI.
Here is my solution. It works fine for me, but YMMV.
Download qunit-karma-setup.js, qunit-karma-launch.js from here
Then, in your Gruntfile:
config.set({
frameworks: ['qunit'],
files: [
'your-app-files-here/**/*.js',
'qunit-karma-setup.js',
'your-tests-here/**/*.js',
'qunit-karma-launch.js'
]
});
Now, you can use omodule(), otest(), oasyncTest() functions to run only the selected modules or tests respectively.
QUnit is not well designed for this, but you can improve it!
The filtering mechanism of QUnit is validTest function that read QUnit.config.filter (string, name of a test). See https://github.com/jquery/qunit/blob/master/src/core.js#L820
There are two problems:
it only allows selecting one test,
you need to know the selected test name in advance (because the tests are filtered when being created).
Suggest changing QUnit to:
filter using a custom "filter" function (the default implementation can do what the current validTest does),
filter the tests when executing (means, collects all the tests first)
Then, implementing inclusive tests will be simple ;-)
I believe you can use only. Taken from the docs:
test('my test 1', function (assert) { ... });
only('my test that will be run exclusively now', function (assert) { ... });
So instead of using word test, you use only.
Add this on the top of your test file
var ttest = test;
test = function() {}
And rename the test you want to run to ttest. Looks clumsy, but simple and works well.

Googletest: combine tests in a testsuite

I am trying googletest.
Previously i have been using Boost test and i have been using the macro BOOST_AUTO_TEST_SUITE to group my tests into a Testsuite.
This makes the junit reports much more readable.
I have not found a hint how to do this or something similar in googletest. Is it possible?
I use the first parameter of the call to TEST() or TEST_F() as sort of a "test suite" identifier, like this:
TEST(TestSuiteName, shouldExpectTrue) {
EXPECT_TRUE(true);
}
TEST(TestSuiteName, shouldExpectFalse) {
EXPECT_FALSE(false);
}
Of course, when using a fixture class with TEST_F(), your TestSuiteName will need to match the name of your fixture class, so it will be necessary to create a separate fixture class for each test suite.
There is no way that I know of to break the test suites into sub-suites or anything like that, but of course you could always run your tests multiple times using the --gtest_filter="someFilter" option if you wanted to clean up your output.