开发者

First time unit testing (in silverlight)

开发者 https://www.devze.com 2023-01-02 20:31 出处:网络
Hi I\'ve searched some other posts, but most of them assumed that people knew what they were doing in their unit testing, and frankly I don\'t. I see the idea behind unit testing, and I\'m coding a开发

Hi I've searched some other posts, but most of them assumed that people knew what they were doing in their unit testing, and frankly I don't. I see the idea behind unit testing, and I'm coding a开发者_运维技巧n silverlight application much in the blind right now, and I'd like to write some unit tests to kind of be sure I'm on the right path. I'd like to be able to use the SL4 vs 2010 silverlight unit test project template, to keep it simple and not use external tools. So what I need an answer for are questions like:

what are the methods of unit testing? what are the differences between unit tests, and automated unit tests? How do I meaningfully unit test in silverlight? What should I be aware of while unit testing (in silverlight) ?

Also should I implement some kind of IRepository pattern in my silverlight app to make unit testing easier?

EDIT:

I will be posting useful links here as I explore this along the way:

Implementing MVVM in silverlight - http://community.infragistics.com/pixel8/media/p/91949.aspx

Mix10 MVVM talk - http://live.visitmix.com/MIX10/Sessions/EX14

Unit testing Ria apps - Link

PK's great resource: http://dotenetscribbles.blogspot.com/2009/12/unit-testing-dependency-injection-and.html


I have never used silverlight unit test project template. I have only used nunit to do unit testing in silverlight. So, I will leave that for someone else to answer. As far as your other questions are concerned:

Unit testing should drive your design. Your unit tests are first users of your code. Your code is based on some expectation and unit tests verify that expectations are being met. Using MVVM pattern (as you are using silverlight), facilitates unit testing. The most important thing to remember is that you have to write testable code. And to write testable code, the most important thing to remember is to inject dependencies. For example, if your code makes a call to the db. You, can't have a unit test making a call to the DB. Instead, you will mock your data acccess layer. This is where concepts like mocks and stubs come into picture. I use moq for mocking in my sivlerlight unit tests. Another, important thing I follow which I think facilitates unit testing is single responsibility principle. Finally, treat your test code as production code, else your tests might give you a false notion, that expectations are being met. Your unit tests are code and hence can have bugs.

what are the differences between unit tests, and automated unit tests?

I am not very sure what do you mean by this. Unit tests are an automated way of white box testing. You can have scripts which run all unit tests, every time you checkin any code in the repository. This can be part of continuous integration.

How do I meaningfully unit test in silverlight

In silverlight, to facilitate testing you should use commands, instead of writing code in code-behind files. This allows you to simulate button click and other GUI events while unit testing. Using MVVM pattern along with commands, you can test all of C# code (not xaml), right up to UI (Converter, VMs, etc).

It is very difficult to mention everything in this one answer. I would suggest, you google for MVVM, commands in Silverlight, Martin fowler - mock are not stubs, mocking frameworks for silverlight, dependency injection

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号