iOS Unit Testing Bundle: Why Is The App Launched? - unit-testing

I have added a Unit Test target and a UI Test target to my application project. When I run the Unit Tests my application is launched. When I run the UI Tests a "special Runner version" of my application is launched. I (barely) understand that the runner version is for producing user actions. But why is my app launched when the unit tests are run? The implication is that my unit tests can interact with the running application but that does not seem to be the case. The whole XCTest environment is new to me. Any clarifications would be just great. Thanks.

I was wrong. It indeed is possible for a unit test to access the running application. I added the following test method and it successfully printed the list and map view controller properties of my application's page view controller:
func testAppAccess() {
if let pageVC = UIApplication.shared.keyWindow?.rootViewController?.childViewControllers[0] as? PageViewController {
print(pageVC.listViewController)
print(pageVC.mapViewController)
}
else { print("Could not obtain the application's page view controller") }
}

Related

Browser Automation Testing with Selenium Web Driver in AWS Code Build

I want to Automate and integrate the the Selenium web driver tests that we developed for a website in AWS code build environment. We want to run these tests automated, in the AWS Code-Build and then Release (AWS Code-Deploy) if all good.
For example, We wrote all of our test cases using node. Let's assume that I have a basic test case like below
npm install selenium-webdriver In a file called google_test.js
const webdriver = require('selenium-webdriver'),
By = webdriver.By,
until = webdriver.until;
const driver = new webdriver.Builder()
.forBrowser('firefox')
.build();
driver.get('http://www.google.com');
driver.findElement(By.name('q')).sendKeys('webdriver');
driver.sleep(1000).then(function() {
driver.findElement(By.name('q')).sendKeys(webdriver.Key.TAB);
});
driver.findElement(By.name('btnK')).click();
driver.sleep(2000).then(function() {
driver.getTitle().then(function(title) {
if(title === 'webdriver - Google Search') {
console.log('Test passed');
} else {
console.log('Test failed');
}
driver.quit();
});
});
Then as you would expect We run this test in the command line,
node google_test
This works fine and great in a manual environment,
however, our challenge is to automate this and deploy automatically if tests were successful,
I wonder how we can archive this in a the AWS code-build setup. Even after doing all the research Im still confused on what is the best way to achieve this, Many suggests many different ways all looks very hacky and unreliable,
Problems/Questions
Since in an Automated AWS code build enr. We dont have browser access, so how can we actually see the output to see if the tests were successful?
What is the way/How we can detect the tests ran correctly to proceed to the next step of code-deploy? what signals can be generated and how?
If this is not possible, what is the recommended way of doing this?

Unable to unit test cloud_firestore live

I'm currently trying to write a unit test that verifies a certain number of documents exist.
This is what I have so far
test('Login with no account', () async {
Firestore _firestore = Firestore.instance;
final QuerySnapshot result = await _firestore
.collection(UserFirestoreField.Collection)
.where(UserFirestoreField.EmailAddress, isEqualTo: 'email#example.com')
.where(UserFirestoreField.Password, isEqualTo: 'wrongpassword')
.getDocuments();
final List<DocumentSnapshot> docs = result.documents;
print(docs);
});
The error I'm getting is
package:flutter/src/services/platform_channel.dart 314:7
MethodChannel.invokeMethod
MissingPluginException(No implementation found for method
Query#getDocuments on channel plugins.flutter.io/cloud_firestore)
I have the android emulator running with my app started.
Every guide I've seen talks about mocking a database, I want to actually check the real database.
Any way to do this in dart/flutter?
Thanks!
In Flutter, unit and widget tests run on your host machine which does not have the native part of your firebase plugin. This is why you are getting this error.
You really should mock the database in tests but if you really want to test your app as close to how it is run by a user you would run an integration test on an emulator.
You can also use a dart based Firebase plugin or use the Firebase REST API.
You can find more about this here: https://flutter.dev/docs/testing
You could JsonDecode into a local map and test the map.

couldn't get Application context

I am writing vaadin test bench (5.0.2) UI test cases with spring boot application and I am writing as #RunWith(Junit4.class) as by writing #RunWith(SpringJUnit4ClassRunner.class) loads something behind the hood and it requires the spring application pre run but I want to test in different environment, which is already up and just one can run the test case and get the Application context from the configuration without running the project is it possible?
I have tried manier things like #Dirtiescontext #SpringRunner etc.But for #RunWith(Junit4.class) no annotations work at the class level so couldn't able to get the Application Context.
#WebAppConfiguration
#RunWith(SpringJUnit4ClassRunner.class)
#SpringBootTest(classes = UIConfiguration.class)
#TestPropertySource(locations = "classpath:testData/testdata.properties")
public abstract class BaseTestCase extends TestBenchTestCase {
//some basic configurations for loading Drivers.
}
I need a configuration for Vaadin based Spring boot project which can provide me Application Context without running anything behind the hood as the #RunWith(SpringJUnit4ClassRunner.class) loads the entire thing.

Karma/QUnit Unit Test External Site

I have a Portal application running on one port--http://localhost:10039. I am trying to unit test individual Ember.js applications, which are loaded into the Portal app via portlets.
What I'd like to be able to do is have those QUnit tests run against the full application, which is running on that other port I mentioned. However, Karma seems to not be fond of running the test suite on a port that isn't the same one on which the application is running.
For example:
test('Page loads in browser', function() {
visit('/login').then(function() {
ok(exists('#login-form'), 'Page loaded successfully');
});
});
... launches Karma successfully on port 9876, but yields...
Page loaded successfully# 42 ms
Expected: true
Result: false
Diff: true false
Source:
at http://localhost:9876/absolute/Users/me/Sites/app/node_modules/qunitjs/qunit/qunit.js:1933:13
at http://localhost:9876/base/tests/unit-tests.js:9:8
at isolate (http://localhost:9876/base/bower_components/ember/ember.js:36720:15)
at http://localhost:9876/base/bower_components/ember/ember.js:36703:16
at tryCatch (http://localhost:9876/base/bower_components/ember/ember.js:45817:16)
at invokeCallback (http://localhost:9876/base/bower_components/ember/ember.js:45829:17)
Is it possible to run my test suite on, say, http://localhost:9876, and have it run its tests against another website/port http://localhost:10039?
The closest I could come to an answer was Karma proxies, though the proxy seems to have no effect. Karma is still running its tests against links relative to its own port 9876.
I would like to add that I am open to other testing frameworks if this can only be done elsewhere--Jasmine, Mocha, etc.
Thanks!
karma is intended for running unit tests, so the code will be loaded in karma client (localhost:9876) and test cases executed there.
If you are planning to run certain end to end tests with your portal application, you could look into alternatives like selenium. In fact, your test above (testing for successful page loading) is a good fit with selenium.

How do you get the python Google App Engine development server (dev_server.py) running for unit test in GWT?

So, I have a GWT client, which interacts with a Python Google App Engine server. The client makes request to server resources, the server responds in JSON. It is simple, no RPC or anything like that. I am using Eclipse to develop my GWT code.
I have GWTTestCase test that I would like to run. Unfortunately, I have no idea how to actually get the google app engine server running per test. I had the bright idea below of trying to start the app engine server from the command line, but of course this does not work, as Process and ProcessBuilder are not classes that the GWT Dev kit actually contains.
package com.google.gwt.sample.quizzer.client;
import java.io.IOException;
import java.lang.ProcessBuilder;
import java.lang.Process;
import com.google.gwt.junit.client.GWTTestCase;
public class QuizzerTest extends GWTTestCase {
public String getModuleName() {
return "com.google.gwt.sample.quizzer.Quizzer";
}
public void gwtSetUp(){
ProcessBuilder pb = new ProcessBuilder("dev_appserver.py",
"--clear_datastore",
"--port=9000",
"server_python");
try {
p = pb.start();
} catch (IOException e) {
System.out.println("Something happened when starting the app server!");
}
public void gwtTearDown(){ p.destroy(); }
public void testSimple() {
//NOTE: do some actual network testing from the GWT client to GAE here
assertTrue(true);}
}
I get the following errors when compiling this file:
[ERROR] Line 21: No source code is available for type java.lang.Process; did you forget to inherit a required module?
[ERROR] Line 30: No source code is available for type java.lang.ProcessBuilder; did you forget to inherit a required module?
As you can see below, I basically want it to be the case that per test it:
Starts a datastore-empty instance of my GAE server
runs the test across the network, against this server instance.
Stop the server
Of course, report the result of the test back to me.
Does anyone have a good way of doing this? Partial solutions are welcome! Hacks are fine as well. Maybe some progress on this problem could be made by editing the ".launch" config file? The only important criteria is that I would like to "unit test" portions of my GWT code against my actual GAE Python server.
Thank you.
I would recommend creating an Ant target for this - take a look at this page for the full ant build file for GWT.
Then, as the first line of the testing target, add an execution task to start the server. Look here for exec docs.
Then set up that ant task in your IDE. This way you get the server running before your tests irrespective of where you run the tests from, and it can be integrated into your build process if you want.