Skip to content

Instantly share code, notes, and snippets.

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

István Pató patoi

👀
...
View GitHub Profile
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')
}
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 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 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 / 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')
}
}
@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.

echo "Type your email, followed by [ENTER]:"
read email
find . -maxdepth 1 -type d \( ! -name . \) -exec bash -c "cd '{}' && git config user.email $email" \;
@patoi
patoi / resource_alloc_docker.md
Created April 28, 2016 09:52 — forked from afolarin/resource_alloc_docker.md
Resource Allocation in Docker

#Container Resource Allocation Options in docker-run You have various options for controlling resources (cpu, memory, disk) in docker. These are principally via the docker-run command options.

##Dynamic CPU Allocation -c, --cpu-shares=0
CPU shares (relative weight, specify some numeric value which is used to allocate relative cpu share)

##Reserved CPU Allocation

@patoi
patoi / RuleSystem.swift
Last active August 16, 2017 18:38
Playing with GameplayKit rule system 1.
//: Check divisible by 3 and 5 with GameplayKit Rule System
import GameplayKit
let divisibleBy3Rule = GKRule(blockPredicate: { system in
(system.state["value"] as! Int) % 3 == 0
}, action: { system in
system.assertFact("divisibleBy3and5", grade: 0.5)
system.assertFact("divisibleBy3", grade: 1)
})