Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to test everything in Xamarin

So i've recently started using Xamarin.UITest in my mobile application. Its great for testing the UI, navigation etc. However im slightly confused as to how the best way is to test all the other parts of the app i.e the database, web connection, model and so on. The project is cross-platform using a shared project.

Should these other tests be in along with the UITests or do they need their own separate project? Furthermore in Xamarin Studio on OSX is there a way to test particularly the .Net only code without having to build and launch the whole iOS app?

Thanks

like image 777
Radical Spin Avatar asked Dec 25 '22 15:12

Radical Spin


1 Answers

This question is really broad.

UI tests should only test the UI itself

  • Does navigation work correctly?
  • Is everything displayed like it should?
  • Are UI components visible, enabled, read-only etc.
  • Do components display correct data?

Your business logic should be tested in a unit test project

  • Do your classes process incoming data correctly?
  • Do they trigger the correct methods with the correct parameters in all cases?
  • Do they prepare the correct calls to webservices, databases or third party libraries? (You don't test the correct behaviour of other pieces of software here)
  • Do they throw exceptions as expected?

Unit tests are helping you the most to fix and avoid bugs. They are in general much more important for high quality code than all the other tests.

Integration tests are used to test the rest

  • Do databases, webservices, file system, operating system API work like expected?
  • Does it all work correctly together?
  • Does it all work fast enough?

There are many good books and links about good testing. It's way too much then to do it here.

Just a few examples:

  • http://blog.stevensanderson.com/2009/08/24/writing-great-unit-tests-best-and-worst-practises/
  • https://developer.xamarin.com/guides/ios/deployment,_testing,_and_metrics/touch.unit/
  • http://blog.falafel.com/hold-right-learning-xamarin-unit-tests/
  • How to do integration testing in .NET with real files?

With these links, StackOverflow and Google you will find out that your unit tests should stay in a separate project. Mock your business logic as good as possible in your UI tests. So that they don't test all your code. Otherwise you will result in UI tests which often fail in order to changes inside your business logic. You would have to change the UI tests everytime you change the unit tests. That becomes annoying and frustrating quickly.

like image 184
Wosi Avatar answered Dec 31 '22 13:12

Wosi