Initial unit testing (in silver)

Hi, I was looking for some other posts, but most of them suggested that people know what they are doing in their unit testing, and to be honest, I do not. I see the idea of ​​unit testing, and now I am coding a Silverlight application much blindly, and I would like to write some unit tests to make sure I'm on the right track. I would like to use the SL4 vs 2010 silverlight unit test project template so that it is simple and does not use external tools. So I need an answer, for example:

What are the unit testing methods? What are the differences between unit tests and automatic unit tests? How do I significantly unit test in silverlight? What should I know during unit testing (in silverlight)?

Also, do I need to implement some IRepository template in my silverlight application to simplify unit testing?

EDIT:

I will post useful links here when I explore this along the way:

Silverlight MVVM implementation - http://community.infragistics.com/pixel8/media/p/91949.aspx

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

Unit testing of Ria applications - http://blogs.msdn.com/b/vijayu/archive/2009/06/08/unit-testing-business-logic-in-net-ria-services.aspx

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

+4
source share
1 answer

I have never used a silverlight unit test project template. I used nunit for unit testing in silverlight. So, I will leave it for someone else to answer. As for your other questions:

Testing your device should guide your design. Your unit tests are the first users of your code. Your code is based on some expectations and unit tests that confirm that expectations are fulfilled. Using the MVVM pattern (when using Silverlight) facilitates unit testing. The most important thing to remember is that you need to write test code. And in order to write test code, the most important thing to remember is to introduce dependencies. For example, if your code makes a call in db. You cannot perform a unit test calling a database. Instead, you will mock the level of data access. Ideas such as layouts and stubs appear here. I use moq for bullying in my sivlerlight unit tests. Another important thing that I follow, which, in my opinion, facilitates unit testing, is the principle of shared responsibility. Finally, treat your test code as production code, otherwise your tests may give you a false impression that expectations are being met. Your unit tests are code and therefore may have errors.

What are the differences between unit tests and automatic unit tests?

I'm not very sure what you mean by that. Unit tests are an automated method for testing white boxes. You may have scripts that run all unit tests every time you check some code in the repository. This may be part of continuous integration.

How I mean unit test in Silverlight

In Silverlight, to facilitate testing, you should use commands instead of writing code in code files. This allows you to simulate button clicks and other GUI events during unit testing. Using the MVVM template along with commands, you can test all C # code (not xaml), up to the UI (converter, virtual machines, etc.).

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

+2
source

Source: https://habr.com/ru/post/1312143/


All Articles