Build and Execute Xamarin.iOS Unit Test from Command Line - unit-testing

I have been trying to run the iOS unit test from command line. I am using Xamarin Studio on Mac for now, I Created a iOS Unit test project as follows
Add New Project --> iOS --> Tests --> Unit Test App
And added a simple Unit test class and its code snippets as shown below:
using System;
using NUnit.Framework;
namespace iOSUnitTest
{
[TestFixture]
public class iOSTestSample
{
public iOSTestSample()
{
}
[Test]
public void MySampleTest() {
Assert.True(true);
}
[Test]
public void MyFailerTest()
{
Assert.False(true);
}
}
}
From Xamarin Studio, I am able to run the application which deploys a app into simulator and execute the test cases. I am trying to automate it through a script.
Till now, I am able to get the Unit Test project build and install the app into the running simulator.
I am not sure how to automate the unit test execution once the app is installed.

This blog post (and the ones linked( might be a bit out-dated but it shows you how to automate unit testing (both simulator and device builds) with the tools that ships with Xamarin.iOS.

Related

Visual Studio for Mac not running unit tests from MSTest project

I've created a .NET Core 6 Web API project in Visual Studio for Mac. I can run the web API without issues and can interact with it using Swagger. I'm now attempting to create a MSTest project and write unit tests. I've written one however when I attempt to run it, Visual Studio for Mac appears not to do anything like so:
Unit Test:
namespace Tests;
[TestClass]
public class UnitTest1
{
[TestMethod]
public void ExampleTest()
{
var text = "hello.";
var result = text.ToUpperInvariant();
Assert.AreEqual("HELLO.", result);
}
}
Any ideas on what I'm missing?

Cannot find element for dotnet test id: error in Resharper 2016.3

I just downloaded Resharper 2016.3 EAP 4 to check out the Unit test functionality with .NET Core. But when I run all unit tests, I get this error:
Cannot find element for dotnet test id:
MvcMovieTests.SimpleTests.TestMethodPassing
Cannot find element for dotnet test id:
MvcMovieTests.SimpleTests.TestMethodFailing
Here are my simple unit tests:
[TestClass]
public class SimpleTests
{
[TestMethod]
public void TestMethodPassing()
{
Microsoft.VisualStudio.TestTools.UnitTesting.Assert.IsTrue(true);
}
[TestMethod]
public void TestMethodFailing()
{
Microsoft.VisualStudio.TestTools.UnitTesting.Assert.IsTrue(false);
}
}
When I run all unit tests with the MSTEST Test Explorer, they run properly and I see the results. But with Resharper 2016.3 I get the two errors above showing up in the Unit Test Sessions window in Visual Studio 2015 Community.
Clearing up the ReSharper caches fixed it up for me. Open the Environment | General page of ReSharper options. Click Clear caches. More information here.

Robolectric different threads in Android Studio vs. Gradle tests

why are thread names different when I start a Robolectric test from Android Studio vs. the Gradle build?
e.g. consider this simple test:
#RunWith(RobolectricTestRunner.class)
public class RobolectricRxThreadTest {
#Test
public void testMainThreadName() {
assertEquals("main", Thread.currentThread().getName());
}
}
when I start this test
directly in Android Studio (by pressing CTRL+SHIFT+F10) the test is okay
but when I start the gradle tests (e.g. from the Gradle projects view: :app - Tasks - verification - test, or from the Terminal view: ./gradlew test) it fails.
The thread name is Thread worker and not main as expected.
I just reproduced the issue, but I wonder why do you need this test?
If you really want to check main thread then the correct way would be:
assertThat(Thread.currentThread()).isEqualTo(Looper.getMainLooper().getThread());
And this test pass from AS and console both runs.

Issues using DataTestMethod and DataRow attributes in MS Test

I have installed MS Test V2 in my VS 2015 instance using nuGet and I have successfully added DataTestMethod and DataRow attributes to my unit tests and they compile, but now when I build, the tests don't show up in Test Explorer.
Example:
[DataTestMethod]
[DataRow("YAHOO", "GOOGLE")]
public void TestCheckSite(string site)
{
... do stuff here ...
}
What am I missing? Is there a Test Explorer upgrade?
[DataTestMethod]
[DataRow("YAHOO")]
[DataRow("GOOGLE")]
public void TestCheckSite(string site) {
...
}
Install MSTest Framework: https://www.nuget.org/packages/MSTest.TestFramework/
If you are building for .NET Core, then install this adapter: https://www.nuget.org/packages/dotnet-test-mstest/
However, if you are building for desktop .NET/UWP, install this adapter instead: https://www.nuget.org/packages/MSTest.TestAdapter/
Now write the tests and build your solution. The tests ought to show up in the Test Explorer.
Please let me know if you still do not see the tests showing up.

How to run tests in Nemerle project

How do I run tests which will test my nemerle code. So for example, I've a Calculator class and a CalculatorTests class in a nemerle project. I have already added a reference to nunit using package manager ("install-package nunit"). Now NUnit is available in nemerle project.
After writing following code
[TestFixture]
class CalculatorTests
{
[Test]
MyTest() : void
{
def result = Calculator().Add( 1 );
Assert.AreEqual( 2, result );
}
}
I tried to use TestDriven.net visual studio add-in to run the test but couldn't able to. Can someone tell me how to run tests in nemerle or do i have to write code to run all tests when executing a console app?
Maybe it caused by NUnit runs under .Net 2.0 runtime. Try to set a runtime version in the NUnit command line.