Is there a possibility to run a particular method only once before the whole set of tests in the .cs file run in Nunit - nunit

I am writing UI tests for a mobile app using Xamarin UI test and N-unit frameworks. I want to run a particular method (App initialization) only once before the set of tests began to run. I used [one time setup] annotation but that is also running before each test.Please help me on this.

You can do this by creating a [SetupFixture] outside of any namespace.
See the docs here: https://github.com/nunit/docs/wiki/SetUpFixture-Attribute

Related

Use openapi service in Flutter Drive integration test, but run into dart:ui problem

The app I am trying to test makes use of feature toggles to enable/disable certain parts of the app. However, the tests I've written are for all the features. When a user logs in, this will fetch the feature toggles from a REST service (using a class which uses the generated openapi) so the app knows what to show and what not to show.
Now I want to include those feature toggles in my tests, so that the corresponding tests are skipped and don't just fail if some parts aren't enabled. However, when I try to include the class that does the call, I get problems with dart:ui in the console, and the test no longer runs. When I (recursively) check the imports on those service classes, there are some imports to widgets.dart, so I guess that's the problem. I tried removing most of it, but since we're using Localized strings for error messages etc. it's getting to be a very cumbersome job to remove all of that from those files.
So before I continue doing that, I was wondering if there is any easy way to include a call to a REST service in an integration test?
I checked the Flutter drive documentation, and searched for some similar questions online but haven't really found anything similar.

How to create test-only routes and views on playframework 2?

I am developing a Play! 2 application that generates some html/js widgets which will be embedded into 3rd-party websites. Their linking are dynamic thus I cannot have static test files.
How can I have test views(and routes to those views) that works only in test mode, so I can test with Selenium.
Basically I want to add testView1.scala.html, testView1.scala.html to test/views and have routes to that, but do not want that these work in production mode. What is a good approach to that?
i'm not sure if this is the best way, but here is how i would do it.
create the test route and route to a test controller
in the test controller, create a wrapped action and have all of your routes use this action
this wrapped action will test to see what mode play is in. if play isnt in test mode, forward to 404, otherwise, run the action
when i get home, ill add some code to support, but this is the general workflow i would use.
hope it helps.
Simples...(now with years to answer..). A bit similar to what #mbseid answered:
Rename your /conf/routes to /conf/prod.routes, and specify it in your /conf/application.conf:
play.http.router = prod.Routes
Create a test routes file, e.g. /conf/test.routes, that exposes the test only route and delegates the rest to the prod routes.
/test/only/something controllers.testonly.TestOnlySomethingController.someMethod()
-> / prod.Routes
Make sure your test only controllers are in a different package than other controllers.
When you start your test application override play.http.router, e.g.:
sbt run -Dplay.http.router=test.Routes
It is a useful pattern in microservices environments with integration tests to expose data not otherwise exposed.
Note, play.http.router used to be called application.router before v2.5+

Adding new test with SenTestCase (new test not showing up in manage scheme)

So I'm trying out this new TDD thing (about time haha). Anyways I have two unit testing files currently one for application and one for logic. The application logic test was autogenerated by xcode and when I go to manage schemes I can see the (void)testExample but I can't see the other tests I have created in my logic file, nor are they being run. Attaching picture.
Well it would help to read the docs a bit more carefully: http://developer.apple.com/library/ios/#documentation/DeveloperTools/Conceptual/UnitTesting/03-Writing_Test_Case_Methods/writing_tests.html#//apple_ref/doc/uid/TP40002143-CH4-SW1
You just have to prepend your methods with 'test'.
i.e.
-(void)testmynewcase {
}

how can I improve iPhone UI Automation?

I was googling a lot in order to find a solution for my problems with UI Automation. I found a post that nice summarizes the issues:
There's no way to run tests from the command line.(...)
There's no way to set up or reset state. (...)
Part of the previous problem is that UI Automation has no concept of discrete tests. (...)
There's no way to programmatically retrieve the results of the test run. (...)
source: https://content.pivotal.io/blog/iphone-ui-automation-tests-a-decent-start
Problem no. 3 can be solved with jasmine (https://github.com/pivotal/jasmine-iphone)
How about other problems? Have there been any improvements introduced since that post (July 20, 2010)?
And one more problem: is it true that the only existing method for selecting a particular UI element is adding an accessibility label in the application source code?
While UI Automation has improved since that post was made, the improvements that I've seen have all been related to reliability rather than new functionality.
He brings up good points about some of the issues with using UI Automation for more serious testing. If you read the comments later on, there's a significant amount of discussion about ways to address these issues.
The topic of running tests from the command line is discussed in this question, where a potential solution is hinted at in the Apple Developer Forums. I've not tried this myself.
You can export the results of a test after it is run, which you could parse offline.
Finally, in regards to your last question, you can address UI elements without assigning them an accessibility label. Many common UIKit controls are accessible by default, so you can already target them by name. Otherwise, you can pick out views from their location in the display hierarchy, like in the following example:
var tableView = mainWindow.tableViews()[0];
As always, if there's something missing from the UI Automation tool that is important to you, file an enhancement request so that it might find its way into the next version of the SDK.
Have you tried IMAT? https://code.intuit.com/sf/sfmain/do/viewProject/projects.ginsu . It uses the native javascript sdk that Apple provides and can be triggered via command line or Instruments.
In response to each of your questions:
There's no way to run tests from the command line.(...)
Apple now provides this. With IMAT, you can kick off tests via command line or via Instruments. Before Apple provided the command line interface, we were using AppleScript to bring up Instruments and then kick off the tests - nasty.
There's no way to set up or reset state. (...)
Check out this state diagram: https://code.intuit.com/sf/wiki/do/viewPage/projects.ginsu/wiki/RecoveringFromTestFailures
Part of the previous problem is that UI Automation has no concept of discrete tests. (...)
Agreed. Both IMAT and tuneup.js (https://github.com/alexvollmer/tuneup_js#readme) allow for this.
There's no way to programmatically retrieve the results of the test run. (...)
Reading the trailing plist file is not trivial. IMAT provides a jUnit like report after a test run by reading the plist file and this is picked up by my CI Tool (Teamcity, Jenkins, CruiseControl)
Check out http://lemonjar.com/blog/?p=69
It talks about how to run UIA from the command line
Try to check the element hierarchy, the table can be placed over a UIScrollView.
var tableV = mainWindowTarget.scrollViews()[0].tableViews()[0].scrollToElementWithName("Name of element inside the cell");
the above script will work even the element is in 12th cell(but the name should be exactly the same as mentioned inside the cell)

jUnit testing with Google Web Toolkit

I would like to be able to run a set of unit tests by linking to them in my application (e.g. I want to be able to click on a link and have it run a set of jUnit tests). The problem is that GWT and jUnit don't seem to be designed for this capability -- only at build time can you run the tests it seems.
I would like to be able to include my test code in my application and, from onModuleLoad for example, run a set of tests.
I tried to just instantiate a test object:
StockWatcherTest tester = new StockWatcherTest();
tester.testSimple();
but I get:
No source code is available for type com.google.StockWatcher.client.StockWatcherTest;
even though I include the module specifically.
Would anyone know a way to do this? I just want to be able to display the test results within the browser.
If you are trying to test UI elements in GWT using JUnit, unfortunately you may not do so. JUnit testing is limited to RPC and non-UI client-side testing. See this thread for a great discussion on what you can and cannot do with GWT jUnit testing.
If you are not trying to test UI elements, but are instead trying to inject your RPC code or client-side logic with test values (hence why you want to be able to click on a link and run a set of JUnit tests), then you should follow the following guide from testearly.com: Testing GWT with JUnit. In short, you should make sure that the method you are testing does not include any UI elements and if the method you are testing is asynchronous in nature, you must add a timer.
In 2.0, HTMLUnit was added. You may wish to use this instead of firing up a browser each time you wish to test.