Java
- JUnit
- Mockito (mostly used, used in Apache Spark)
- EasyMock
- jMock
- Powermock
- JMockit (has many functionalities, works well in Scala)
- private members
Need to change a little bit, for Scala
Scala
- ScalaCheck (inspired by the Haskell library Quickckeck)
- property-based testing for Scala
- ScalaMock
- Testing => assures some conditions
- Informal reasoning => results in invariants
=> Informal reasoning is more important! (TDD is not perfect, invariants are so tricky)
def foo(x, y) = x/y
Three scenarios:
- bug
- not a bug because caller is not supposed to give y = 0
- not a bug because the author has verified => it is only a result of informal reasoning!
- in Scala, the condition checking function is much simpler
- Pros : no unit test required, faster code remind
while() {
assert { loop invariant }
}
assert { Thread.holdsLock(someLock) }
Informal reasoning on concurrency control
Thinking Process
- According to design, the invariant must hold
- But it fails!
- There must be something wrong
- Now lets backtrace and fix the bug
ex. invariants connecting two modules
- Many many invariants makes a powerful code.
- Once we have enough assertions, now we can afford aggressively optimizing the
- Much easier and safer when extending/modifying modules
=> Brings an evidence for another action
- Involve all the components in the system
- cli, master worker, ..
- Designate one or more waypoints in the execution path
- However, integration test itself is very hard, and requires an amount of design
- Assume production requirements
- (e.g.) running process is killed, communication with a node suddenly fails, running node crashes
- Stress tests
- (e.g.) use skewed data