parallel execution of tests in same class in mstest - mstest

I am trying to execute test cases in same class parallely using MStest framework.
I have used .runsettings(maxcpucount) file and testsettings(paralleltestcount) file but these are only running tests of different projects in parallel.I am unable to achieve this when I have tests in same class.

You should be able to do this, by changing your run setting the following way. When you define the scope level to Method instead of ClassLevel, you would be able to run tests present in same class in parallel.
<?xml version="1.0" encoding="utf-8"?>
<RunSettings>
<!-- MSTest adapter -->
<MSTest>
<Parallelize>
<Workers>10</Workers>
<Scope>MethodLevel</Scope>
</Parallelize>
</MSTest
>
</RunSettings>

You cannot run in-class tests in parallel using MSTest. Microsoft has this in their backlog tasks (microsoft github).
In the mean time you can use NUnit to achieve this. Try this blog: http://approache.com/blog/from-mstest-to-nunit/
Parallelization using NUnit with Selenium: Try this videos: Part 1, Part 2

Related

Best way to decouple integration test cases from build (gradle spring-boot)

I am working on a large project and need to offer users the ability to optionally enable or disable local integration test cases ( For pipeline, test cases must be enforced).
First of all, welcome to the community.
Next, you can modify the test task inside the build.gradle file or maybe add a new task called integrationTest and implement your custom logic there.
As an instance, you can check this gist on Github: Separating tests from integration tests with Gradle
You can also use #Profile annotation to your integration test classes and run your tests with different profiles. You can read more about profiles using the following link: Spring Profiles

Is it a fallacy to have a 'tester goal'?

Well, I would like to have a maven goal execute-custom-tests inside my custom-maven-plugin that consists of running test methods (This tests are not unit tests). Something similar to test goal of soapui-pro-maven-plugin, for example.
Why? Basically the main objectives of the plugin are testing stuff (not unit testing) and the tests in src/test are for unit testing, right?
Being more specific I was thinking about something like this:
#Mojo (name = "run-custom-tests", LifecyclePhase.TEST)
public class TesterMojo extends AbstractMojo {
#Parameter(property = "someParameter")
private String someParameter;
// [...] parameters for test configuration
#Override
public void execute() throws MojoExecutionException, MojoFailureException {
// Piece of code that executes a set of custom tests which procedure I specified.
}
}
When test fail, I would like them to be marked as failed tests not as failed executions. What's the right thing to do here? Show me the light, please.
Maven conventions support two types of testing out of the box: unit tests (via maven-surefire-plugin) and integration tests (via maven-failsafe-plugin).
By default, maven-surefire-plugin only looks for the following files with unit tests:
**/Test*.java
**/*Test.java
**/*TestCase.java
Similarly, default includes for integration tests run by maven-failsafe-plugin are the following:
**/IT*.java
**/*IT.java
**/*ITCase.java
So, as you can see, Maven lets each plugin figure out which tests it should care about. So it's perfectly fine for src/test/java to contain different types of tests, not just unit tests.
Different folder
You can put tests in a different folder too. One example would be if you have non-Java tests, since then src/test/java location doesn't make sense. Standard Maven plugins get project model from Maven to figure out the src/test/java location and some 3rd party plugins use the same mechanism. Depending on the plugin you use, you might want to check out its configuration or use maven-build-helper-plugin to add-test-source in order for some plugins to pick up another test folder automatically.
Different tests on demand
From the Maven perspective the core difference between unit tests and integration tests is the additional requirements for the later: they often need to have your project already packaged and they often need additional setup or teardown. But you yourself can set up multiple test goals during both test and integration-test phases. All major test frameworks support specifying which test suite should be run when (e.g., via groups). If your framework doesn't, you can still use plugin includes/excludes. It is a standard practice to combine this with Maven profiles in order to only run smoke tests by default (during development) and to run full tests on CI environment. You can use the same approach to enable anyone (a tester?) to run extra tests on demand, e.g., to run extra heavy tests when certain important part of the code has changed.

Junit Toolbox WildcardPatternSuite with different Suffix?

I'm using Junit toolbox to run my unit and integration tests. It's working fine. Now, I have created another layer of tests that I would also like to run with junit toolbox but with a different suffix, not *IT or *Test.
#RunWith(WildcardPatternSuite.class)
#SuiteClasses("**/*BCT.class")
public class AllBCTTests {
}
But these tests are not running in my Maven build. What do I have to do to get these tests with a different suffix to run?
The above piece of code works. Different suffixes can be used with WildcardPatternSuite.

What exactly is thread-count parameter in maven

I am new to maven and I am not quite sure what is the difference between thread-count ="1" and thread-count = "2"
If I set thread-count ="2" , it means that the same test will run on the same time on both of the phones?
Is it possible to run a test on one phone and when it finished, to run the same test on the second phone?
Thanks
Without further information my best guess is Parallel builds in Maven 3:
Maven 3.x has the capability to perform parallel builds.
...
This build-mode analyzes your project's dependency graph and schedules modules that can be built in parallel according to the dependency graph of your project.
The next best guess is Run appium tests parallelly.
And the next is TestNG's documentation, 5.10.2 - Parallel tests, classes and methods:
The parallel attribute on the <suite> tag can take one of following values:
<suite ... thread-count="5">

Report failures in TestNG framework

I have developed TestNG framework and implemented Maven
When I run the script, the results are generated and in the target folder, when I open index.html, all the scripts are displayed as Pass though it failed.
I have used java verifications (reporter.log)
Can someone suggest me on how to change the java verifications to TestNG to view the failures?
Thank in advance
Reporter.log is just for logging statements in the report. You need to use assertions to do your verifications. Try out the Assert class in Testng.

Resources