// Production code:def abs(i: Int) return (i < 0) ? i * -1 : i// Test code:for (line: String in File(prod_source).read_lines()) switch (line.number) 1: assert line.content equals def abs(i: Int) 2: assert line.content equals return (i < 0) ? i * -1 : i
// Production code:def process(w: Work) firstPart.process(w) secondPart.process(w)// Test code:part1 = mock(FirstPart)part2 = mock(SecondPart)w = Work()Processor(part1, part2).process(w)verify_in_order was_called part1.process(w) was_called part2.process(w)
class UserInfoValidator { public void validate(UserInfo info) { if (info.getDateOfBirth().isInFuture()) { throw new ValidationException()); } }}
public class UserInfoService { private UserInfoValidator validator; public void save(UserInfo info) { validator.validate(info); // Throw an exception if the value is invalid. writeToDatabase(info); }}
assertEquals("March", monthMap.get(3)); // JUnitassertThat(monthMap).containsEntry(3, "March"); // Truth
ImmutableSet<String> colors = ImmutableSet.of("red", "green", "blue", "yellow");assertTrue(colors.contains("orange")); // JUnitassertThat(colors).contains("orange"); // Truth
npm install -g protractor
webdriver-manager update & webdriver-manager start
// It is a good idea to use page objects to modularize your testing logicvar angularHomepage = { nameInput : element(by.model('yourName')), greeting : element(by.binding('yourName')), get : function() { browser.get('index.html'); }, setName : function(name) { this.nameInput.sendKeys(name); }};// Here we are using the Jasmine test framework // See http://jasmine.github.io/2.0/introduction.html for more detailsdescribe('angularjs homepage', function() { it('should greet the named user', function(){ angularHomepage.get(); angularHomepage.setName('Julie'); expect(angularHomepage.greeting.getText()). toEqual('Hello Julie!'); });});
exports.config = { seleniumAddress: 'http://localhost:4444/wd/hub', specs: ['testFolder/*'], multiCapabilities: [{ 'browserName': 'chrome', // browser-specific tests specs: 'chromeTests/*' }, { 'browserName': 'firefox', // run tests in parallel shardTestFiles: true }], baseUrl: 'http://www.angularjs.org',};
protractor conf.js
1 test, 1 assertions, 0 failures