Is there any MsBuild property $(???) for Unit Test executions? - msbuild

I am trying to assign a condition to a "Target",
With the intention of evaluating whether the compilation is produced by the test run or not
img Run All Tests
img Singel Test
But, I do not know what property to use $(?????)

Related

Unable to provide CLI arguments to `cargo test`

I used to be able to run specific, named tests from the command-line interface like this: cargo test <test_name>. But now this gives me the error
running 1 test
error: Found argument '<test_name>' which wasn't expected, or isn't valid in this context
Other arguments to cargo test also don't work.
The line that causes the error is this line in the test setup:
let cli_default_args = Arc::new(cli_args::Args::from_args());
Where the cli_args::Args struct is a struct that holds the value of the command line arguments and the from_args function comes from the StructOpt package derivation. cli_args::Args is decorated with #[derive(StructOpt)].
The problem was that arguments intended for cargo test were interpreted as arguments for the application.
Replacing the problematic line in the test setup
let cli_default_args = Arc::new(cli_args::Args::from_args());
with
let cli_default_args = Arc::new(cli_args::Args::from_iter::<Vec<String>>(vec![]));
fixes the problem. The above code means that your test setup runs as if the program didn't get any CLI arguments, everything is running with its default values.

Karate API framework- test dependency

In my regression suite I have 600+ test cases. All those tests have #RegressionTest tag. See below, how I am running.
_start = LocalDateTime.now();
//see karate-config.js files for env options
_logger.info("karate.env = " + System.getProperty("karate.env"));
System.setProperty("karate.env", "test");
Results results = Runner.path("classpath:functional/Commercial/").tags("#RegressionTest").reportDir(reportDir).parallel(5);
generateReport(results.getReportDir());
assertEquals(0, results.getFailCount(), results.getErrorMessages());
I am thinking that, I can create 1 test and give it a tag #smokeTest. I want to be able to run that test 1st and only if that test passes then run the entire Regression suite. How can I achieve this functionality? I am using Junit5 and Karate.runner.
I think the easiest thing to do is run one test in JUnit itself, and if that fails, throw an Exception or skip running the actual tests.
So use the Runner two times.
Otherwise consider this not supported directly in Karate but code-contributions are welcome.
Also refer to the answers to this question: How to rerun failed features in karate?

Is there a way to test roblox games?

As I started to understand a little bit more about Roblox, I was wondering if there is any possible way to automate the testing. As a first step only on the Lua scripting, but ideally also simulating the game and interactions.
Is there any way of doing such a thing?
Also if there are already best practices on doing testing on Roblox(this includes Lua scripting) I would like to know more about them.
Unit Testing
For lua modules, I would recommend the library TestEZ. It was developed in-house by Roblox engineers to allow for behavior driven tests. It allows you to specify a location where test files exist and will gives you pretty detailed output as to how your tests did.
This example will run in RobloxStudio, but you can pair it with other libraries like Lemur for command-line and continuous integration workflows. Anyways, follow these steps :
1. Get the TestEZ Library into Roblox Studio
Download Rojo. This program allows you to convert project directories into .rbxm (Roblox model object) files.
Download the TestEZ source code.
Open a Powershell or Terminal window and navigate into the downloaded TestEZ directory.
Build the TestEZ library with this command rojo build --output TestEZ.rbxm .
Make sure that it generated a new file called TestEZ.rbxm in that directory.
Open RobloxStudio to your place.
Drag the newly created TestEZ.rbxm file into the world. It will unpack the library into a ModuleScript with the same name.
Move this ModuleScript somewhere like ReplicatedStorage.
2. Create unit tests
In this step we need to create ModuleScripts with names ending in `.spec` and write tests for our source code.
A common way to structure code is with your code classes in ModuleScripts and their tests right next to them. So let's say you have a simple utility class in a ModuleScript called MathUtil
local MathUtil = {}
function MathUtil.add(a, b)
assert(type(a) == "number")
assert(type(b) == "number")
return a + b
end
return MathUtil
To create tests for this file, create a ModuleScript next to it and call it MathUtil.spec. This naming convention is important, as it allows TestEZ to discover the tests.
return function()
local MathUtil = require(script.parent.MathUtil)
describe("add", function()
it("should verify input", function()
expect(function()
local result = MathUtil.add("1", 2)
end).to.throw()
end)
it("should properly add positive numbers", function()
local result = MathUtil.add(1, 2)
expect(result).to.equal(3)
end)
it("should properly add negative numbers", function()
local result = MathUtil.add(-1, -2)
expect(result).to.equal(-3)
end)
end)
end
For a full breakdown on writing tests with TestEZ, please take a look at the official documentation.
3. Create a test runner
In this step, we need to tell TestEZ where to find our tests. So create a Script in ServerScriptService with this :
local TestEZ = require(game.ReplicatedStorage.TestEZ)
-- add any other root directory folders here that might have tests
local testLocations = {
game.ServerStorage,
}
local reporter = TestEZ.TextReporter
--local reporter = TestEZ.TextReporterQuiet -- use this one if you only want to see failing tests
TestEZ.TestBootstrap:run(testLocations, reporter)
4. Run your tests
Now we can run the game and check the Output window. We should see our tests output :
Test results:
[+] ServerStorage
[+] MathUtil
[+] add
[+] should properly add negative numbers
[+] should properly add positive numbers
[+] should verify input
3 passed, 0 failed, 0 skipped - TextReporter:87
Automation Testing
Unfortunately, there does not exist a way to fully automate the testing of your game.
You can use TestService to create tests that automate the testing of some interactions, like a player touching a kill block or checking bullet paths from guns. But there isn't a publicly exposed way to start your game, record inputs, and validate the game state.
There's an internal service for this, and a non-scriptable service for mocking inputs but without overriding CoreScripts, it's really not possible at this moment in time.

How to add prerequisite check in a googletest test suite?

I have a test suite with multiple unit tests, and all these unit tests expect specific working directory as they use relative path to load some test data. If unit test executable is executed from some wrong directory, all these unit tests fail.
What's the proper way to make this check in gtest? Preferably so that I get one single failure message instead of having 50 failed unit tests with the same message.
One way is to use fixture and do single time check, but in that case I still get all these 50 unit test failures instead of skipping the rest of the test suite
In the latest release v.1.10.0 gtest provides the new GTEST_SKIP() macro (hooray!!).
It can be used as follows:
TEST(SkipTest, DoesSkip)
{
if (my_condition_to_skip)
GTEST_SKIP();
// ...
}
As far as I know, there is no documentation on this yet except for the unit test of the feature.
As you can see in the unit test, entire fixtures classes can also be skipped. The skipped tests are marked as not failing with a green color. But you still get one output per test:
[----------] 2 tests from Fixture
[ RUN ] Fixture.DoesSkip
[ SKIPPED ] Fixture.DoesSkip (1 ms)
[ RUN ] Fixture.DoesSkip2
[ SKIPPED ] Fixture.DoesSkip2 (0 ms)
[----------] 2 tests from Fixture (12 ms total)
Googletest has built-in filtering feature. Provided that all your tests have common part of the name (e.g. they are in single fixture), you can disable them when running tests:
./foo_test --gtest_filter=-PathDependentTests.*
Or by setting environment variable GTEST_FILTER to the same string
GoogleTest 1.8 docs
Googletest master docs
If you still want a failure but only one instead of fifty then it's probably not the best mechanism unfortunately.

How to get disabled test cases count in jenkins result?

I have suppose 10 test cases in test suite in which 2 test cases are disabled.I want to get those two test cases in test result of jenkins job like pass = 7 ,fail = 1 and disabled/notrun= 2.
By default, TestNG generates report for your test suite and you may refer to index.html file under the test-output folder. If you click on "Ignored Methods" hyperlink, it will show you all the ignored test cases and its class name and count of ignored methods.
All test cases annotated with #Test(enabled = false) will be showing in "Ignored Methods" link.
I have attached a sample image. Refer below.
If your test generates JUnit XML reports, you can use the JUnit plugin to parse these reports after the build (as a post-build action). Then, you can go into your build and click 'Test Result'. You should see a breakdown of how the execution went (including passed, failed, and skipped tests).