Skip to content

Instantly share code, notes, and snippets.

View patoi's full-sized avatar
👀
...

István Pató patoi

👀
...
View GitHub Profile
@patoi
patoi / WebDriver_Mocha
Last active April 9, 2018 03:16
Selenium WebDriver JavaScript test with Mocha and NodeJS
/*
* Selenium WebDriver JavaScript test with Mocha and NodeJS
*
* Start with: SELENIUM=PATH_TO_SELENIUM_JAR/selenium-server-standalone-2.31.0.jar mocha -t 10000 -R list google-sample.js
*
* Download selenium-server-standalone-2.31.0.jar from https://selenium.googlecode.com/files/selenium-server-standalone-2.31.0.jar
* 'sudo su' and 'npm install -g colors mocha selenium-webdriver'
*
* http://visionmedia.github.io/mocha/
* https://code.google.com/p/selenium/wiki/WebDriverJs
it('your test', async function() {
let args = ... // your test data
let result, error // variables: test and guard in the finally block
try {
result = await testFunction(args)
} catch (err) {
error = err
} finally {
it('is OK - better way', async function() {
let result, error
try {
result = await testFunction(true)
} catch (err) {
error = err
} finally {
expect(error).to.be.undefined() // guard: handling code flaw
expect(result).to.be.equal('OK')
}
it('is not OK - better way', async function() {
let result, error
try {
result = await testFunction(false)
} catch (err) {
error = err
} finally {
expect(result).to.be.undefined() // guard: handling code flaw
expect(error.message).to.be.equal('not OK')
}
@patoi
patoi / code.js
Last active April 3, 2018 09:10
Testing async/await
async function testFunction (isOK) {
if (isOK === true) {
return 'OK'
} else {
throw new Error('not OK')
}
}
it('is not OK - bad!', async () => {
try {
let result = await testFunction(false)
// flawed tests __pass__ instead of throws an error!
} catch (err) {
expect(err.message).to.be.equal('not OK')
}
})
it('is not OK - not bad, but it could be better', async () => {
try {
let result = await testFunction(false)
expect.fail()
// flawed test throws an ugly error:
} catch (err) {
// ...'AssertionError: expected 'expect.fail()' to equal 'not OK''
expect(err.message).to.be.equal('not OK')
}
})
it('is OK - not bad', async () => {
let result = await testFunction(true)
expect(result).to.be.equal('OK')
// flawed test throws an error, but it is not a test error (AssertionError)
})
@patoi
patoi / start_testing_java8_today.asciidoc
Last active February 28, 2018 11:44 — forked from aslakknutsen/start_testing_java8_today.asciidoc
Example of how to use both JDK 7 and JDK 8 in one build.

JDK 8 Released

Most of us won’t be able to use/deploy JDK 8 in production for a looong time. But that shouldn’t stop us from using it, right?

It should be possible to sneak in JDK 8 in the back way, the same way we snuck in Groovy and other libraries we wanted to use.

The Test Suite to the rescue

The Maven compiler plugin run in two separate lifecycles, compile and testCompile. Those can be configured separately.

@patoi
patoi / SwiftComponentsAndEntities.swift
Created October 11, 2015 08:14
Swift Components and Entities
//: Playground - noun: a place where people can play
import GameplayKit
class ShootingComponent: GKComponent {
let power: Int
init(power: Int) {
self.power = power