Unit Testing Monotouch under Visual Studio - visual-studio

I have a Monotouch iOS application that I'm writing in Visual Studio using Xamarin's new Visual-Studio plug-in.
I would like a way to execute my Unit tests from within Visual Studio (e.g. with the Resharper runner).
I don't much care which unit testing tool I used (they're currently written as nUnit tests).
I know Xamarin supports Touch.Unit which will allow me to run on the device or simulator, but this is too long of a cycle-time, I need it to run on my windows machine.
I tried to use NUnitLite, but this still has the problem of not being able to run on the windows machine.
I also attempted to use the Visual Studio Solution configurations, which should, theoretically allow me to choose a different build configuration in the drop-down to switch between windows (for my cross-platform core library + its tests) and Monotouch (for the IOS UI app, cross-platform library, and IOS tests), but in this, the project references didn't automatically switch to the other framework, or I just messed up how to properly setup a secondary build configuration.
Finally, using two different solution files and separate sets of project files is not ideal because one needs to switch and also keep the clone project's files in sync.
Any ideas on the best way to accomplish easy, fast, unit testing?

The way I've made this work in the past is:
Have all your core code in a regular .Net 4 library. This library
has no dependencies on iOS or Android.
Write tests against the core library in another .Net 4 project, using NUnit Lite syntax in your asserts. Use ReSharper to run them all you like.
If you wish, setup an iOS project to run the tests in a simulator - link-in all the files for the tests
On iOS or Android, you will need to link-in the files from the core project.
If you have any platform-specific code in your tests, you won't be able to run them with ReSharper.
If you want to see an example, we took this same approach with Xamarin's Field Service app.

Related

I have a small Vulkan project in VS C++ that runs on Windows. Can I make it run on Android in the same solution, supporting both Windows and Android?

I want my project to run on windows, and I want the ability to also run on Android. Basically one project that can run on two (or more) targets.
If not in VS, is there another way to accomplish this?
If you want a project that can be built both for Windows and Android, I suggest you look into creating a CMake project. CMake can be integrated both with VS and with Android Studio.
However, if you haven't done any Android NDK development, I suggest you start out with some Android-only examples first.
As an example, I work with a fork of Sascha Willem's Vulkan examples. In my fork I have a cmake file that is used both to generate Visual Studio projects, and also referenced by the Gradle build file for the Android build.
EDIT: removed incorrect statement about VS not supporting Android at all.

Debugging Xamarin Android apps if I'm using VSTS hosted builds / HockeyApp

I have been developing a Xamarin Android app using Visual Studio Community 2015. So far, everything has been working well for debugging, as I simply build my app in VS, and connect my phone to my laptop and debug it using F5.
Recently, I started using HockeyApp for crash reporting, so that as I'm using my app (during the day when I'm not programming), if it crashes, I can send crash reports. This works OK, but the crash reports don't include line numbers, and also I don't have good references to what build of the app crashed, as the app itself isn't actually getting uploaded to HockeyApp, nor are the debugging symbols.
To help with this, I'm trying to get more organized using Visual Studio Team Services, doing hosted builds upon checkin of my source code, and automatically uploading the app and debugging symbols to HockeyApp.
Now I'm trying to reconcile in my mind how this is supposed to all work for me. If I'm coding in VS and debugging through VS, the app is getting deployed to my phone. But now, I check in the source code, and VSTS does a CI build and uploads everything to HockeyApp. But now, the CI build that VSTS did isn't really the same build that's on my phone, since that build came from the Visual Studio build.
So, when I'm done coding then later in the day, I run my app and it crashes, I'm concerned that the crash report from HockeyApp isn't actually going to relate to what Hockeyapp has. For one, I may not have done a check-in to the source control, in which case, my phone will have a newer version than HockeyApp has. But even if I had remembered to check it in, it's really not the same "build" (since my phone has the APK that was built by Visual Studio and HockeyApp has the APK that was built by VSTS).
Questions:
1) Is there a way to upload my app and debug symbols directly from Visual Studio, without going through a VSTS build? (preferrably automatically upon every build, so that I don't have to remember to do an extra step)?
2) If not, what are the best practices to resolve the issues that I mentioned above?
Ideally, I don't want to have to do any extra steps when I'm done coding for the day. I want to be able to always know that the last version that I built and deployed to my phone will have been uploaded to HockeyApp, so that if it crashes, the crash repo that HockeyApp sends will match with the correct source code and debug symbols.
For your first question, This depends on the project you working on. If you are working on a UWP project, there is an "Enable Crash Analytics" option and "Distribute With Hockey App" option allow you to do this when you right click on the project. But if you are working on a Xamarin.Android project, there is no option to do this. You need to upload them to Hockey App manually. However, you can create a power-shell script to upload these files to Hockey App and configure this power-shell script as post-build event. You can check the power-shell script here for reference: upload_file.ps.
And for the Visual Studio Team Services(VSTS) build, you just need to make sure that the app version and build configuration is totally the same as you debugging through VS from your local machine. Hockey App will detect the version automatically and send the data to the related build version.

Error in building and running Xamarin iOs application in visual studio 2015 preview

I am the newbie in Xamarin Cross Platform development. I am using Visual Studio 2015 Preview for development. I created the new solution for mobile app and it is working correct for both Droid and Windows phone. But after successful connection with iOs Build host I got the error when I build the iOs App like -
Xamarin.iOS does not support running or debugging the previous build version of your project.Please ensure your solution builds before running or debugging it.
And also when I click on View iOS Simulator I got build host error.
Error: Build version problem. it will show the build version problem.
Please tell me the solution for this.
Most common cause of those symptoms
The most likely cause of this issue is the following known bug:
https://bugzilla.xamarin.com/show_bug.cgi?id=25811
Explanation
The problem in that bug is that the Xamarin.Forms template is using a bad default setting for the iOS project in Visual Studio's configuration manager.
The configuration manager works by telling Visual Studio which projects you want to be built and/or deployed at the same time in the configuration you're using at the time.
So for example; when you build your Android project in Forms, the configuration manager makes sure that the shared project is included; otherwise it wouldn't work, or you'd have to build it separately or etc. etc. (i.e. a real pain.)
Normally, Visual Studio doesn't have a way to automatically "know" which project(s) you want to include in all your configurations; you'd have to tell it to include (some library) with (some app); etc. manually.
How to fix it
Screencast: http://www.screencast.com/t/zLoQOpEn
Go to "Build -> Configuration Manager"
Select the configuration(s) you wish to adjust, (e.g. Debug | iPhoneSimulator, Release | iPhone)
Make sure your shared library project(s) are included with the platform-specific configurations. (You can ignore the greyed-out 'Deploy' checkboxes, those are handled automatically)
Why this is a bug
So this isn't a bug in that the configuration manager isn't working correctly for iOS projects, but that the Forms template is using a bad default setting for the iOS projects when you create a new app. It should "know" to include the shared project in the iOS configurations by default.

Developing for tablets using Phonegap

i'm starting development with phonegap for tablets and need to clarify some issues.
1) as i understood, i can work in any IDE: Visual Studio, Idea, XCode. All what i need from IDE is emulator to test some specific things, for example interacting with file system, or making JSONP requests to some site's API. Is this true?
2) after developing of application for one single platform, i can take the 'www' folder and build it for other platforms using PhoneGap Build, isn't it?
3) is there any way to emulate tablet in visual studio?
1) You need the IDEs for target-platform-specific coding. If you want to make a PhoneGap plugin for Windows Phone, you'd use Visual Studio for the native part. If it were a plugin for iOS, you'd use Xcode.
If you don't want to use PhoneGap Build, you can also build packages for the target platforms using the respective IDEs.
IDEs are also the primary way to test your application, since you can't easily test
features specific to a mobile device in your browser. If you have the SDKs for your target platforms installed, the respective IDEs should feature a way to run an emulator. You will probably have to set up a project for your app, according to the instructions here.
2) Generally, your application should run on any supported platform, as long as you stick to the PhoneGap API. Some features might behave differently on different platforms, so you'll still have to test throroughly on all platforms you indend to support.
3) If you install the Windows Phone SDK, you can use an emulator. There is some information on what the emulator is capable of on MSDN.

Is it possible to build a Monotouch application in Visual Studio?

I would like to know if it is possible to compile a Monotouch project that does not have any reference to any UI library in Visual Studio. This project only use the Monotouch framework.
I have done some research and I read that, if the project don't have any reference to the Apple SDK , I should be able to build a MonoTouch project using Visual Studio. If I can, do i need some particular configuration to achive my goal.
Some related links:
How easy is it to develop an iPhone application using MonoTouch in Visual Studio?,
How can I develop for iPhone using a Windows development machine?,
iPhone development on Windows
Even if your project doesn't have any references to MonoTouch libraries, it is still a MonoTouch library project. Visual studio doesn't recognize that project type and because of that you can't really compile the code.
I wrote about this a while ago, and how you can change your project so you can actually use Visual Studio for development (although you won't be able to run the app) here:
http://escoz.com/blog/developing-with-monotouch-on-windows-and-visual-studio
Hope that helps.
There is a Visual Studio addin that may help. It hasn't been updated in a while though. Also, this would only help you write the code. To compile and run the code, you will still need MonoTouch and a Mac. https://github.com/follesoe/VSMonoTouch
Update : As of February, 2013 Xamarin includes Visual Studio support for developing iOS apps in their Business sku of Xamarin.iOS. You can fully develop on Windows + Visual Studio, but still need a Mac on your network to perform builds and run the simulator.
If you're talking about building a DLL or library in VS.NET that you could then use in a MonoTouch project, I believe the answer is NO. To be usable in MT, the code has to be compiled with MT.
The MonoDevAssist VS extension (search VS Extension Manager for "monotouch") seems to work perfectly. There are just a couple of easy steps to follow post-installation, which are documented here:
http://monodevassist.codeplex.com/documentation

Resources