Run unit tests without building main application - objective-c

I have an application that uses the Vuforia SDK (https://www.vuforia.com/) and a feature that does not work in the simulator. I started writing unit tests for this application and I'm not sure why but when I run the tests, it also tries to build the main application and fails because there is no valid architecture for i386.
Is is possible NOT to build the main application? I'm only testing a couple of model classes and a XML parser, no need to build the whole application...
Thanks !

You could put the classes that need testing into a library or framework and make the tests depend on the library. These tests and library will not require the Vuforia SDK.
The executable is a separate target (or even project) depending on the library but is built after the tests.

The unit test target that is created for new projects is an Application Unit Test. It injects your test code into the app by setting BUNDLE_LOADER and TEST_HOST in the build settings. You can create a new unit test target and by default this will be a Logic Unit Test (BUNDLE_LOADER and TEST_HOST are not set). Then add the code you want to test to the new target as well as your app target. Change your scheme to the new target and run your unit tests.
New Target Dialog
Target Membership
Select Scheme

Related

How do I define an entry point for a project that has nothing but nUnit tests?

How do I define an entry point for a project that has nothing but nUnit tests?
I have a bunch of nUnit TestFixture() classes that instantiate classes that return SQL data. The TestFixture classes have TestFixtureSetUp that contain all the parameters they need to instantiate the classes they’re using for tests.
I can run Unit Test Sessions in ReSharper, but I need to run the project in Debug and the entry point I have is a Windows Form. So how do I kick off and debug the tests? I thought nUnit had a test list that would fire the tests in order... Do I need an nUnit test constructor? so this is either an entry point question or an nUnit test list question.
Thanks!
How do I define an entry point for a project that has nothing but nUnit tests?
You don't. A test project is typically compiled as a library (DLL), not an executable, which means it doesn't require an entry point.
Instead of executing the project as an exe, you should just debug the tests. This is often done, when using nUnit, by attaching the debugger to the nUnit process then running the tests. However, tools like TestDriven.Net will simplify this further by allowing you to directly debug from within Visual Studio. Given that you're using ReSharper, you should be able to choose to debug from within Resharper as well.

Alter TFS Build in order to deploy before executing tests

As I'm using Selenium/MSTest for UI tests, I got a problem: I need to deploy an ASP.NET site to a staging server just before the automated tests are executed during a TFS build (TFS 2012).
Although I thought I could do this configuration in the TFS Build process template (DefaultTemplate.xaml), I can't figure out how to change the order to execute a Build->Deploy->Test flow.
Note I've found some how-tos aiding in this goal when using TFS Lab Environment, but this isn't my case.
Default Template Unit Testing is different from UI Testing. Default template is designed to run Build -> Unit Test -> Deploy.
You are now in Build -> unit Test -> Deploy -> UI Test.
For UI Testing, You need separate Test Agent and set up build agent in interactive process.
These links may help
http://www.deliveron.com/blog/post/Configuring-a-TFS-2010-Team-Build-Server-to-Run-Coded-UI-Tests.aspx
http://blogs.infosupport.com/testing-your-web-application-with-selenium-and-mtm-part-1/
http://blogs.infosupport.com/testing-your-web-application-with-selenium-and-mtm-part-2/
Finally I've solved the problem chaining builds.
For example, when I queue a production build, this is the sequence:
Build, deploy to staging without UI tests
Build, no deploy, staging UI tests only
Build, deploy to production without UI tests
Build, no deploy, production UI tests only
I got the solution from this blog post:
http://blog.stangroome.com/2011/09/06/queue-another-team-build-when-one-team-build-succeeds/
Post's author posted the modified DefaultTemplate.xaml (build definition) in GitHub Gist:
https://gist.github.com/jstangroome/1196590/
Credits for the whole blogger!
One simple solution is to have an intermediate msbuild project file that is specified in your build definition and from there, call the actual solution file.
You can then do whatever is required pre- or post- build to ensure that the environment is up and running prior to TFS executing the tests. We do things like compile and deploy databases prior to TFS running our integration tests.
This is one solution that avoids having to manipulate the build template.

Xcode4: Profiling Unit Tests

I have an Xcode project with a framework target and a separate target for unit tests. Since there is no executable target I can't run the profiling tools without creating a new target, linking against the framework and profiling it that way. However, this means I have to move a lot of code around which unreliable and annoying.
Is there a way I can run the profiling tools (mainly Allocations) on my testing target?

Unit tests in Sonar

Is it possible to run unit tests when a non-maven project is analyzed with Sonar, in Sonar light mode?
Sonar doesn't run unit tests. But it should be able to analyze existing unit tests reports. From Reuse in Sonar unit test reports generated by other systems:
2. Using Sonar in its full capability in an ANT environment
If you are using ANT to build your
applications, the main weakness so far
in Sonar was that it did not allow to
display Unit tests results nor Code
coverage. I am sure that now you have
read the first use case, you know that
by using the
“-Dsonar.dynamicAnalysis=reuseReports”
parameter, this limitation does not
exist anymore. You simply need to
specify where those reports to reuse
are going to be found, by using the
following properties :
sonar.cobertura.reportPath,
sonar.clover.reportPath,
sonar.surefire.reportsPath...

Unit testing an iPhone static library with XCode 3

I am writing a number of static libraries for the iPhone and wish also to have suites of unit tests. XCode 3 provides templates for both static libraries and unit tests but I am wondering how they should fit together in a static library project?
In my static library project I have created a target for unit testing but expect to also create an executable to kick off the unit tests than run against the classes in the static library.
What is the procedure for doing this?
Note that some classes of tests (like anything that would rely on the system calls such as [UIApplication sharedApplication] working require a separate target, while pure logic tests do not.
Create a new project with Unit Test and see what is added - basically you can do the same thing easily, create a new target and select "Unit Test Bundle" as the target type.
you have to add all your .m related files in the unit test target. (Just drag and drop!)
In case people still have problems with using static libraries:
I've created an article that explains how to create static libraries and how to use them within projects:
Xcode: The complete explanation on how to use static libraries:
http://www.sodeso.nl/?p=822
And for the unit testing part of static libraries, i don't have an explanation on how to set it up but i do have created a static library template that uses Google Toolkit for Map unit testing framework which you can download and add to your Xcode installation:
Xcode: Static library template with Google Toolkit for Mac Testing framework:
http://www.sodeso.nl/?p=982