Does Nunit have a way of alerting me a test has failed when an If validation fails - visual-studio

I have imported my Visual Studio Tests into Nunit Test Runner. The tests are set up using If Validations so the tests will run all the way through. The Tests are written in C# using Selenium Webdriver to drive them with an Nunit Framework. After I run the Test i see Pass but I see 0 Assertions which is correct because I never added them but I did add If's should I see an output of some kind to these failing like I would in Visual Studio?
I have goggled this and looked through Nunit documentation and Visual Studio and not found the exact answer.

Looks like you want to check a few cases within the same test. This is not a good idea. Here is a good explanation why.
If you rewrite tests with the single-assert-per-test approach then you will see it is OK to use assertions rather than validations. Assertions will work exactly how you do need:
They don't interfere other cases (because the other cases are in the other tests)
They alert NUnit that each validation is failed (because that is what alerts for).
Hope that helps.

you can use multiple assertions in a single test case. I have used this approach with MSTest (Not with NUnit). You can use try catch blocks in your test case. This will allow you to catch the failed Assertions and your test will continue. At the end of test case, you can check the number of failed assertions. If the count is greater than 1, you can forcefully fail that test case, else you can continue to your next test case.
This approach is explained with example in this blog post.
http://www.binaryclips.com/2016/03/coded-ui-test-testing-all-assertions-in.html

Related

Cypress 10 - How to run all tests in one go?

I used to use Cypress 9 on previous projects.
By default, when running cypress open or cypress open --browser chrome used to run all tests for all React components.
However I installed Cypress 10 for the first time on a project that didn't have e2e tests yet. I added test specs, but I don't see any option to run all tests altogether.
It seems I have to run the tests one by one, clicking on each of them.
Can anyone please suggest how do I run all the tests automatically?
It's been removed in Cypress v10, here are the change notes related
During cypress open, the ability to "Run all specs" and "Run filtered specs" has been removed. Please leave feedback around the removal of this feature here. Your feedback will help us make product decisions around the future of this feature.
The feedback page to register your displeasure is here
You can create a "barrel" spec to run multiple imported specs.
I can't vouch for it working the same as v9 "Run all tests", but can't see any reason why not.
// all.spec.cy.js
import './test1.spec.cy.js' // relative paths
import './test2.spec.cy.js'
...
As #Constance says, reinstated in v11.20.
But still a very handy technique if you want to run a pre-defined subset of your tests.
In Cypress version 11.2.0 the Run All button has been reinstated.
You need to set experimentalRunAllSpecs to true in cypress.config.js.
Please see Configuration - End-to-End Testing
If Cypress Test Runner is not a must, I suggest to utilize the CLI/Node Cmd approach
You can trigger all the test(s) by npx cypress run(Still the video recording & screenshot on failed steps would be saved in the respective folders) to run all or with any other cypress flags to filter out specific spec files, or browser etc.
As per the feedback discussion there is a workaround the same as #Fody's answer that will achieve the same result as v9. Also worth noting though is the section on Continuous Integration and the Update 1 that includes a fix for preventing this workaround creating issues with the cypress run command.
Are there any current workarounds?
Yes. If you are impacted by the omission of this feature, it is possible to achieve the same level of parity as 9.x with a workaround Gleb Bahmutov explains here: https://glebbahmutov.com/blog/run-all-specs-cypress-v10/
This will still inherit the same problems as the previous implementation (which is why it was removed) but it will work in certain cases where the previous implementation was not problematic for your use case
https://github.com/cypress-io/cypress/discussions/21628#discussion-4098510
It was removed because people used it wrong.
The Test Runner is for debugging single tests. But by running all tests, then performance will quickly become a problem and crash the entire suite.
Running all tests should only be performed from the CLI.
Sources
https://github.com/cypress-io/cypress/issues/681
https://github.com/cypress-io/cypress/discussions/21628

Is there a way to associate and execute protractor tests to MTM test cases?

Here's the background:
I've wrote my tests in protractor#visual studio and got it running successfully with the help of this guide;
Checked the project into TFS;
Now, my intention is to associate my protractor tests to microsoft case tests, then i intent to run against a environment (SCVMM).
I tried Coded Ui Test, but i found then a little bit slow.
Is there a way that i can get this done?
Thanks.
What I did was use Generic Tests to accomplish this.
Each Generic Test you create can represent a Protractor test. I just named them similarly. Then you can link the Generic Test to the MTM test. Simple as that.
I took it a step further and set the Generic Test up in such a way that it runs the Protractor test. This is really nice because Visual studio will recognize these tests in Test Explorer. So no more command prompt :)
Here's an example of one of mine:

Can ReSharper run unit tests automatically

Is it possible to automatically run unit tests while you work without compiling or running them manually? I am aware that NDepend allows you to do so, but I would prefer to use the ReSharper suite.
This has been available since dotCover 10. See the dotCover documentation for details.
This adds a new panel "Continuous Testing Session" as well as a new status icon in the gutter.
Note that Visual Studio also has this feature, known as Live Unit Testing.
Not possible with Resharper at the moment, you will need something like NCrunch that runs your unit tests continuously in the background, highlighting code that breaks them as you write it and fails your tests.
Edit: At the time of my response it wasn't possible to do this with ReSharper but now in Version 10 it is, see Drew Noakes's answer. You could still give NCrunch a try as it continuously runs your tests in the background even without doing an explicit save.

easiest way to get continual unit tests running locally with visual alerts, with xUnit for C#/VS2008?

I'm currently using MSTest in VS2008 for unit tests, but I am looking at going to xUnit.net.
Question - What would be the easiest way to get my unit tests running continually locally (on my PC) and with some sort of visual alert of pass / # of fails.
i.e. similar to what we do in Ruby on Rails with autospec.
THanks
PS Intersested in hearing of the simplest open source option too.
You should also ask this on http://xunit.codeplex.com/Thread/List.aspx
There's an xUnit GUI runner and it has an auto-reload when DLLs get touched.
The missing bit is the auto-rerun of the last of executed tests when that happens. The minute we have that, you're just a Shift F6 (compile current project) away from waht you want.
The xunit.net guys are normally quite responsive, and avote on [my] http://xunit.codeplex.com/WorkItem/View.aspx?WorkItemId=8832 would help.
Regarding your other comment - I really believe xUnit.net is worth your effort using. You won't look back.
Resharper's test runner runs within VS, can run just a single test or a whole suite, and appears to support xUnit with a plugin.

Is there an API for running Visual Studio Unit Tests programmatically?

Is there an API for running Visual Studio Unit Tests programmatically?
Running MSTests.exe with Process.Start() does not work in the current scenario. What I'm looking for is something like the NUnit SimpleTestRunner.
Any ideas?
/Erik
You're correct in that there's no public API for the mstest framework. I wrote a manual replacement for mstest one day to see how hard it was, and it's not as simple as it looks (particularly if you want to take advantage of more than one CPU core), so beware of going down this path.
Personally I've always just run mstest.exe programatically and then parsed the resulting .trx XML file. Are there any particular reasons why you can't use Process.Start to run it?
P.S. Some of the strange behaviour of mstest.exe are solved if you pass the /noisolation command line parameter - give that a go if you feel so inclined :-)
Update: Erik mentions he wants to run the test API in the current thread so he can set the thread culture for globalization issues.
If you run a unit test under the debugger, you'll notice that mstest creates a bunch of threads, and runs all your tests in different threads, so this isn't likely to work even if you could access the API.
What I'd suggest doing is this:
From your test "runner" application, set an environment variable
Run mstest pointing it at the specific tests
Add a [ClassInitialize] (or [TestInitialize]) method which reads this environment variable and sets the culture
Profit!
After taking a deep dive with reflector into MSTest.exe and further down into the Visual Studio Unit Test stack, I found that the API used by MSTest is sealed up and made private so that i cannot be used from the outside.
Why not using Reflector and seeing how NUnit SimpleTestRunner is running the tests... And then use this technique...
You can make use of the Microsoft REST API's for TFS to run ms tests. Please refer to the documentation here.
I've linked to "Call a Rest API" so that you can see how you'd go about calling one of the REST API's for TFS.
Note that if your tests are linked to the build, they should run automatically every time a build is queued.
Here is the link to Run Functional Tests.
I've also discovered an article on using the TFS SDK API to run tests. Here is that link as well: Link to API Article

Resources