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.
Related
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.
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") }
}
I am using Django 1.8 and I have a management command that geocodes some items in my database, which requires an internet connection.
I have written a test for this management command. However, the test runs the script, so it also requires an internet connection.
After pushing the test to GitHub, my CI is broken, because Travis doesn't have an outside internet connection so it fails on this test.
I want to keep this test, and I'd like to continue to include it in python manage.py test when run locally.
However, is there a way I can explicitly tell Travis not to bother with this particular test?
Alternatively, is there some other clean way that I can keep this test as part of my main test suite, but stop it breaking Travis?
Maybe you could decorate your test with #unittest.skipIf(condition, reason) to test for the presence of a Travis CI specific environment variable to skip it or not. For example:
import os
...
#unittest.skipIf("TRAVIS" in os.environ and os.environ["TRAVIS"] == "true", "Skipping this test on Travis CI.")
def test_example(self):
...
If the external resource is an HTTP endpoint, you should consider using vcrpy to record and replay the HTTP requests/responses.
This way you can continue running the same test suite in different environments. It'll also speed this test up.
I have deployed an OSGI bundle which is currently using a running FTP Server import some files , and saved the data in the Resource ( JCR / FS ) as provided .
For the time being considering JCR , I have written sling unit test bundle which returns test results after hitting the SlingJunitServlet . What is the best way i can invoke the test bundle from the client side ?
The SlingRemoteTestRunner allows JUnit tests that run as part of a Maven or other build to act as proxies for server-side tests that the SlingJUnitServlet runs.
See the ServerSideSampleTest example in the testing/sample/integration tests module.
I have a REST API server that uses Express, Mongoose and config. I want to unit test my API. Basically, bring up a temporary web server on port x, an empty mongo-database on port y, do some API calls (both gets and puts) and validate what I get back and then shutdown temporary server and drop test database once my tests finish. What is the best way to do this? I have been looking at mocha/rewire but not sure how to set up temporary server and db and not sure what the best practices are.
I use Jenkins (continuous integration server) and Mocha to test my app, and I found myself having the same problem as you. I configured Jenkins so it would execute this shell command:
npm install
NODE_ENV=testing node app.js &
npm mocha
pkill node
This runs the server for executing the tests, and then kills it. This also sets the NODE_ENV environment variable so I can run the server on a different port when testing, since Jenkins already uses port 8080.
Here is the code:
app.js:
...
var port = 8080
if(process.env.NODE_ENV === "testing")
port = 3000;
...
test.js:
var request = require('request'),
assert = require('assert');
describe('Blabla', function() {
describe('GET /', function() {
it("should respond with status 200", function(done) {
request('http://127.0.0.1:3000/', function(err,resp,body) {
assert.equal(resp.statusCode, 200);
done();
});
});
});
});
I found exactly what I was looking for: testrest. I don't like its .txt file based syntax - I adapted to use a .json file instead for my specs.
I'd recommend giving Buster.JS a try. You can do Asynchronous tests, mocks/stubs, and fire up a server.
There its also api-easy build on top of vows, seems to be easy to use the first, but the second its much flexible and powerful
There is no right way, but I did create a seed application for my personal directory structure and includes the vows tests suggested by #norman784.
You can clone it: git clone https://github.com/hboylan/express-mongoose-api-seed.git
Or with npm: npm install express-mongoose-api-seed