Last active
January 31, 2018 09:01
-
-
Save sebv/50c3481ab33ebd9b93cb to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(); | |
}); | |
}); | |
}); |
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
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?
(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
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.