I have experience unit testing but I have never unit tested a Xamarian solution.
My question is should I add two unit test projects to my solution? One would be a MSTest or NUnit test that tests the logic and another project Xamarian.UITest that only tests the UI? From my browsing on the internet it seems the Xamarian.UITest is only able to test the UI? Is this true or can you test the logic as well?
Thanks.
Don't try to make Xamarin.UITest test the entire application. Use Xamarin.UITest to automate the testing of the UI and, providing you have a decent separation of concerns, use xUnit, NUnit, etc, to test the logic part(s) of your app.
Related
I was working on setting up Selenium in a project today, and the thought came to mind: "Should I be using the NUnit framework in correlation with my Selenium tests?"
Here's my concern with using the NUnit framework: From the NUnit website, it states that: "NUnit is a unit-testing framework for all .Net languages". The purpose of the framework is to build unit tests, not integration tests.
Selenium tests are typically (I don't know of any instance when they aren't) integration tests. So, going back to my question, is it good practice to use a unit testing framework to do integration tests? Are there integration test frameworks that are robust enough to compete with NUnit, of which would be more appropriate?
The two main options for .NET development are, for the most part, NUnit, and MSTest. IMHO, neither are very well optimized for automated browser tests.
You can force each to do what you want, but features such as TestNG's #DataProvider are a pain to implement, especially if you are dynamically changing your data provider for each test (say, loading your browsers to test through a properties file) -- this is trivial with TestNG, but NUnit and MSTest take a significant amount of "hacking" to make it work.
TL;DR version: Someone really needs to port TestNG over to .NET :)
I am new to testing so please bear with the obvious unfamiliarity.
I have a solution with multiple projects, configurations and app settings. There is already a compiler directive to warn on non-Release builds but this is often ignored. I'm looking for a more visible warning during testing. Something that acts as a checklist for testers to do before they can proceed.
I have a unit test project in the solution. There are three questions here:
Can a unit test be set up to run as a post-build event?
Is there a way to prevent publishing the solution in non-Release mode?
Is using a unit test trigger standard practice?
If there are other alternatives, what are they?
We use Visual Studio 2010 Ultimate with tests written in MSTest. Both our unit tests and integration tests* are written in MSTest.
**By our definition, an integration test is an MSTest TestMethod that takes a while to run and/or calls out to external components such as a database or web services.*
I'm looking for a way of easily filtering out the integration tests so that only unit tests run without all the integration tests running too.
My ideas so far:
Mark integration tests with the [Ignore] attribute. This works but is a real pain when you do want to run the integration tests.
Assign a [TestCategory] attribute to the different test types. This allows them to be run separately but only through the Test View panel. You can't use CTRL+R, A (Run All Tests in Solution) or other similar shortcuts/hotkeys.
The integration tests are in a separate project, is there something that could be done to stop them running at the project level? As long as it's easy to toggle.
Write the integration tests in a different test framework, e.g. NUnit. This would keep them totally separate from a tooling point of view.
Does anyone have any other suggestions? Are there any plug-ins that can help with this?
I recommend having a different project (or projects) for integration tests because depending on your runner the only real way to run or not run tests across all runners is to include or not include a test class library.
But, I also recommend, if you're using MSTest, to use the TestCategoryAttribute to tag non-unit tests. You can then "filter" tests to be run in Test View with MSTest.
Runners like Resharper and apparently TestDriven.net (http://bit.ly/tmtYC2) allow you to then filter-out those tests from general unit-test executions.
If your unit test project is in a separate namespace, you could use the keyboard shortcut CTRL+R, T to run all tests in the current context (i.e. namespace MyApp.Tests.Unit). To do this place the cursor just after the opening curly brace in the namespace clause of any unit test class.
I have a suggestion but you won't like it.
Abandon MSTest entirely, while other unit test frameworks have been evolving MSTest as almost stopped in time. Yes, it has a major benefit of integrating directly with VS, but if I'm not mistaken that will change in VS 2011 which will provide native support for custom unit test runners integration.
(Note: The stopped in time part may be not true because I confess not paying to much attention to MSTest since I used it sparingly with VS 2008)
I use NUnit and separate my unit tests from the integration tests by using a different class library project. Then I automate the running of the tests using Gallio command line runner allowing me to configure separate scripts for running unit and integration tests.
Finally, personal opinions aside, I'm not sure but the TestDriven.net plugin may have support for running tests with a specific category only, so you could check that.
I'd like to add UI tests to an iOS project, in the same manner as OCUnit tests.
I know there is the Instruments + UIAutomation JavaScript approach, but I don't see how that fits into an automated build workflow. Can you setup Instruments + UIAutomation scripts as build dependency for example?
Secondly, I'd rather write the UI tests in the same language as the rest of the code...
Are there any alternatives / things I'm missing?
Thanks.
Martijn
You can actually use OCUnit for UI testing.
If you're already familiar with OCUnit, this piece of code is a good start:
How to do UI Testing of iOS Applications Using OCUnit
You can then run these tests automatically with xcodebuild. It's not straightforward, but worth the extra work. I recommend to take a look at this post: Xcode4: Running Application Tests From The Command Line in iOS
UIAutomation can also be automated now with instruments, but the fact that you can now run your UI tests with OCUnit makes it less interesting.
Have a look at FoneMonkey by Gorilla Logic. This might be what you are looking for.
I've been using Visual Studio 2008 Test projects to store my tests. Lately I've realized that a lot of my unit tests are in fact integration tests because they rely on external sources (e.g. file system, SQL server, registry).
My question is, what is a good approach to separating out integration tests from unit tests?
Ideally I want only the unit tests to show up in the Test View, because I run them frequently during development. The integration tests on the other hand I don't want in the Test View because I will only run them infrequently, e.g. when I'm about to make a build drop.
Keep them in separate projects, and keep the integration testing projects out of your day-to-day Visual Studio solutions.
When you wish to run the integration tests, you can use a different solution that includes them. If you don't want to wait for a second instance of VS to load, you can run them from the command-line.
I put them in a separate project named IntegrationTests or something similar.
EDIT:
With Test View you can create lists & filter them:
http://msdn.microsoft.com/en-us/library/ms182452.aspx
And then run them:
http://msdn.microsoft.com/en-us/library/ms182470.aspx