I have a problem with Unit testing a Xamarin Android project.
My setup:
Shared Xamarin project
ClientX.Android
ClientX.iOS
Native.Android
Native.iOS
Native.Android contains no resources, no MainActivity and no Androidmanifest. It's just shared Mono.Android code and normal business logic for it.
I have an Xunit testing project with which I have been able to test the Shared Xamarin project.
I need to test some business logic that is contained inside Native.Android but I get an error (which does make sense to me):
Severity Code Description Project File Line Suppression State
Error NU1201 Project Client.XXXX.NativeDroid is not compatible with
netcoreapp3.1 (.NETCoreApp,Version=v3.1). Project
Client.XXX.NativeDroid supports: monoandroid12.0
(MonoAndroid,Version=v12.0) XXX.UnitTests
I can't find how I should go about Unit tests inside a Xamarin Android project that is not view/UI related.
I managed to find the answer.
Using this project: https://github.com/xunit/devices.xunit
You can run Platform specific (iOS/Android) unit tests (not UI tests). See the "Integration" folder in that project for examples of projects. Update the dependencies, add the references to the other projects you need inside Visual Studio and it should work for your own Xamarin 5 project.
Related
I am trying to use xunit to unit test a project I have. I have created a new .Net core class Library project and referenced the other project, but the classes I want do not show up.
This is the project.json file in the test project(I know there is no xunit yet)
Resharper knows it is there, but when I press the option nothing happens.
UPDATE: Project.Json for WeatherMob
You need to reference your main project in your test projects project dependencies.
"dependencies" : {
"NETStandard.Library" : "1.6.0",
"WeatherMob": "1.0.0-*"
}
Also this will only work if the directory structure is correct. Meaning the WeatherMob and Test project need to be in the same folder.
/src
--WeatherMob
--WeatherMobTests
I have a local nuget package which contains a single test. The test is decorated with [TestClass] and it's test method is [TestMethod].
The reason this is a nuget package is because this test will be brought in to any test projects in order to test that a t4 transform has occurred in the referenced assemblies. The t4 template generates classes dynamically and I want the test to run to verify the t4 template has been executed (using reflection to make sure the generated classes have the expected methods)
When I reference the nuget package, the Visual Studio Test Explorer never displays the test. I was under the impression that VS reflected over the types in the assemblies to build it's test list, but that seems to be an incorrect assumption.
Is there a configuration setting or something that I am missing in order to have the test discovered?
Thank you,
Jason
Visual Studio Test Explorer can only run tests from multiple test projects in a solution and from test classes that are part of the production code projects.
There are two workarounds for your scenario:
Run the test from command line.
Instead of placing the generated dll file in the nuget package, placing the test class file in the "content" folder of the nuget package. This will add the test class file to your project when install the nuget package and then Test Explorer will detect the tests after building the solution.
I have visual studio solution. It contains 4 projects.
Main project (tested project), built as .lib
Wrapper project that contains just main and runs Main project, built as .exe
Google Test project which builds google test library, buit as .lib
UnitTest project that uses 3. and 1., built as .exe
I am using GoogleTestAdapter so my unit test from project 4. are available through visual studio's test explorer and I can test my project just fine.
The problem is that when i run code coverage using Microsoft's code coverage tool I am not getting any coverage results for my Main project. I can only see code coverage for Google Test project (3.) which is weird since both Main project and Google Test project are set up the same way.
Classes from my Main project are not present in code coverage report. I can only see them there if I actually write some tests for that classes and even then code coverage for that classes is 0%.
I have a solution which containes serveral projects (An MFC Application and the others are DLL projects). Is it possible to add another console application project (BOOST TEST) to unit test a specific DLL project, without modifying anything in the production MFC application and succeeding in building the whole solution?
I want only the test console application to run as a post build and then launching the prodution MFC application.
I wrote a series of blog posts on test-driven development in C++ that show you step-by-step how to do TDD in C++ with Visual Studio and Boost.Test. The steps would be nearly identical for your situation with the exception that your console test project depends on the DLL project instead of the static library project that I used in my article.
If I understand you correctly you want the build of the solution to compile and run the tests. If you say "build and run in the debugger" (F5), you want to compile all the code, run the tests and then run the application if the tests pass. This is not hard to do.
Set up the console unit test program as outlined in my blog posts and that will make the unit test project compile and run as part of the build. So if you say "build and run in the debugger" (F5) in Visual Studio, it will build the solution and then run the startup project, e.g. your MFC application. Since the solution contains the unit test console executable project, it will build that project. The unit test project has the post-build step to execute the tests, so the tests will run as part of the build.
Because your unit test executable depends on a DLL, you will need to make sure the DLL is found by the executable at run-time. You may need to add additional commands to your post-build step to copy the DLL to the necessary directory before running the test executable. You can verify this works properly by setting your unit test project as the startup project and running it in the debugger.
Double check in the configuration manager that all the projects are set to build for your combination of platform and configuration. Sometimes if you have customized these in your solution when you add a new project it isn't automatically checked to compile in the custom platform/configuration combination.
If this isn't working for you, then add a comment or edit your question to include more specifics about what isn't working.
We're developing a Qt project using the Code::Blocks IDE with the QtWorkbench plugin. We'd like to take advantage of Qt's unit testing modules to test our code, but from what I've read online, the only way to do so is to use qmake to manually create a new "project" and makefile for each unit test and then to build and execute that project.
Does anyone know of a way to integrate tests with our overall project to have them built and run automatically when the project is built, specifically within the context of Code::Blocks?
http://www.archivum.info/qt-interest#trolltech.com/2008-09/00297/Re:-Usage-of-QTestLib.html
http://qtcreator.blogspot.com/2009/10/automatically-running-unit-tests.html