How to unit test Silverlight 3 Out-Of-Browser application? - silverlight

How to unit test Silverlight 3 Out-Of-Browser application?

Roy Osherove has created an open source framework to test silverlight controls
It called SilverUnit and it uses Typemock in order to intercept .NET calls and fake their behaviour.
SilverUnit lets you test your controls using simple unit testing framework no browser required.
Seems like a good solution for what you're looking for.

Since you are into beta stuff (Silverlight 3), are you willing to consider using VS 2010?
If so, take a look at Mathew Aniyan's blog. He has lots of information on data driven Coded UI Tests.

Related

Selenium for WPF UI automation testing

Can I use Selenium to do WPF UI automation testing?
Support for WPF automation exists in WPF itself. Check out AutomationPeer. This article might help. This article is more detailed. All this is good if you want to automate interaction with the UI itself (the usefulness of which is debatable).
Another course of action is to unit test the business logic without touching the UI - if the application uses MVVM then the loose coupling between View and ViewModel should make unit testing a breeze. I get the impression that you're more into automating the UI though.
Yes, you can use Appium which is based on Selenium.
There is a pretty good introductory blog post by Scott Hanselman: WinAppDriver - Test any app with Appium's Selenium-like tests on Windows.
You'll need the WinAppDriver that "supports testing Universal Windows Platform (UWP) and Classic Windows (Win32) apps on Windows 10 PCs".
Selenium can be used to automate only web applications. If your WPF is an windows application you can not automate it.
If you WPF application runs in a web browser using XBAP, still you will not be able to automate the application. So the answer is NO.

Unit Testing in Lightswitch

I'm thinking of running unit tests for the business logic in the Lightswitch application. I've added a Silverlight unit test project (from the Silverlight Toolkit), however I couldn't retrieve the code from Lightswitch to write tests on.
Or is there really no way and the best way is to move the code out to another Silverlight class library?
Ended up creating a separate test project, then adding the code to be tested through the "Add as Link" option. This way I was able to unit test the code even if the logic is inside the Lightswitch project.
You can test custom LightSwitch code by using the GoF bridge pattern, see https://github.com/legg/UnitTestingLightSwitch2011

Automated Silverlight 5 Unit testing for business logic

Our team is using Silverlight 5 for development as it has features we require going forward. I have discovered that NUnit doesn't work as standard as it isn't Silverlight and that the tools available for Silverlight testing appear to primarily be aimed at running within browsers and are a pain to automate it seems.
However a lot of the code I want to test is the View Models which aren't specifically Silverlight, so I was hoping there is a way of using NUnit or similar to just test this and integrating into a build server (which is currently being decided upon)
So, is it possible to test Silverlight in this way?
I haven't tried it but looks interesting:
http://statlight.codeplex.com/
and what about third parties (maybe Telerik offers something on their testing suite).
I know it's no ideal, but if it's just VM and non dependant on UI you can link the files to a WPF project and execute the unit tests (in our case we had to share two versions the SL and the WPF one that's why we chose to test our VM in the WPF version :-)).
The unit testing from Silverlight (toolkit) I haven't found a way to link it to an automated build process
The best solution I have found is AgUnit:
http://agunit.codeplex.com/
AgUnit is an open source plugin for ReSharper. This solution of course assumes that you're using ReSharper. AgUnit allows you to run Silverlight unit tests in the ReSharper test running. Unfortunately, I just checked the AgUnit site and it looks like they only support Silverlight 5. You may want to head over there and find out about their plans for supporting Silverlight 5 though as it is a great plugin.
Prior to using AgUnit, we were using Statlight and found it to be pretty good as well, just not quite as convenient as AgUnit.

Silveright UI testing with SpecFlow

We use SpecFlow with Selenium successfully to test our HTML applications and are looking for a similar way to test our Silverlight applications. At the moment, we are assessing these options:
SpecFlow Silverlight with Microsoft Silverlight unit test framework
Normal SpecFlow using Telerik WebAii
Has anyone tried these approaches? Can Microsoft framework test UI elements (eg click on button, assert on text value)? Are there other options?
I created a blog entry for Silverlight Unit Testing and specflow here
http://rburnham.wordpress.com/2011/05/13/testing-silverlight-asynchronous-code-with-specflow/
just note that this was a pre release built, they may have changed the syntax a bit.
but it sounds like your after UI Tests. You can use the Coded UI Tests with specflow to achieve this. I wrote a series on this as well
http://rburnham.wordpress.com/2011/03/15/bdd-ui-automation-with-specflow-and-coded-ui-tests/
To summorise you would need to do the following
Create a Test Project
Set up specflow for that project
Add a reference to your silverlight app (not the test project) for SilverlightUIAutomationHelper.dll. This allows the Coded UI Test to hook into the silverlight app
Now getting them to work together is basically the same as by second link
Just a note though Coded UI Tests do not work with out of browser silverlight apps and i think its only silverlight 4.

What unit testing tools should I use for Silverlight 4?

I'm starting up a brand new project using VS2010 and Silverlight 4. This is my first Silverlight project and I'm at a loss as to what tools I should use for both mocking and unit testing. There's Rhino.Mocks 3.5 for Silverlight, but the author marked it as an alpha release. Moq claims Silverlight support, but I've not used it before. As far as unit testing, there are a few options, but a lot of the information out there seems a bit dated.
So what are the best unit testing tools to use on a new Silverlight 4 project?
You can use Nunit, Silverlight Unit Testing Framework
, StatLigt for unit testing.
For mocking try moq. It is linq to mocks.

Resources