Skip to content

Instantly share code, notes, and snippets.

@sebv
Last active January 31, 2018 09:01
Show Gist options
  • Save sebv/50c3481ab33ebd9b93cb to your computer and use it in GitHub Desktop.
Save sebv/50c3481ab33ebd9b93cb to your computer and use it in GitHub Desktop.
var sinon = require('sinon'),
support = require('appium-support'),
Q = require('q'),
chai = require("chai");
should = chai.should();
function actualLogic(cmd) {
return support.core.exec("sleep 10000 && " + cmd).then(function(res) {
return res[0].toUpperCase();
});
}
describe('example', function() {
it("should work", function() {
var mock = sinon.mock(support.core);
mock.expects("exec").once().withArgs('sleep 10000 && echo "hello world"').returns(new Q(['hello world', null]));
return actualLogic('echo "hello world"').then(function(res){
res.should.equal('HELLO WORLD');
}).finally(function(){
mock.verify();
mock.restore();
});
});
});
@sebv
Copy link
Author

sebv commented May 1, 2015

cc @jlipps @Jonahss @moizjv @imurchie. This is the kind of thing we need to do if we want fast and extensive unit tests, just skip the slow logic. (It can also be used to get rid of complexity after modules have been extracted).

If you write this kind of test at the same time as you are coding, a lot of designs issues with become apparent. As a rule of thumb if you cannot write tests the code needs reformatting.

@penguinho
Copy link

It should be pretty easy to add this for my last commit. I have a file I can use that will be an example for when two devices are connected

@Jonahss
Copy link

Jonahss commented May 1, 2015

Nice @sebv, so the point is to remove the actual Exec call, leaving that for e2e testing, and here we just test the logic of our lib.

Do we still put e2e tests in a submodule, or only all the way through appium?
We did decide to switch to Bluejay instead of Q, right?

@Jonahss
Copy link

Jonahss commented May 1, 2015

(It also looks like @mentions don't work in gists?)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment