Title: Theory / Unimportant / CS / Programming / Java / Junit / 4
Tags: automatedNewLineAfterCommaSpace seen_description declaration todo_declaration
On every note of this deck, unless a note says otherwise:
Language: java

Question: In which order are tests executed
Answer: Random order
Page: https://github.com/junit-team/junit4/wiki/Test-execution-order

Instruction: @FixMethodOrder(MethodSorters.JVM)
Page: https://github.com/junit-team/junit4/wiki/Test-execution-order
Effect: Tests are run in order returned by JVM

Instruction: @FixMethodOrder(
  MethodSorters.NAME_ASCENDING
)
Page: https://github.com/junit-team/junit4/wiki/Test-execution-order
Effect: Tests are run in order returned in ascending order of method name

Instruction: @OrderWith(orderable_class)
Page: https://github.com/junit-team/junit4/wiki/Test-execution-order
Meaning: Order the tests in the order of runnable
Language: java
Context: test

Instruction: assertThrows(
  throwable_class,
  lambda
)
Page: https://github.com/junit-team/junit4/wiki/Test-execution-order
Effect: Fail unless `lambda()` throws an exception of type throwable_class
Context: test
Returns: the throwable thrown by `lambda` if the test succeed

Question: What is the advantage of `assertThat` over `assertEquals`, `assertTrue` etc...
Answer: "assert that foo is bar" reads like english
Page: https://github.com/junit-team/junit4/wiki/Matchers-and-assertthat
Context: junit
Answer2: It allows for more detailled error message in complex test
Answer3: Can be combined for more complex tests with or, each...

Instruction: assertThat(
  var,
  matcher
)
Page: https://github.com/junit-team/junit4/wiki/Matchers-and-assertthat
Effect: fails if the matcher fail on var
Context: junit

Instruction: allOf(matchers)
Page: https://github.com/junit-team/junit4/wiki/Matchers-and-assertthat
Context: junit matcher
Returns: A matcher that match if all of the matchers match the input
Variables: matchers a list/array of matcher

Instruction: anyOf(matchers)
Page: https://junit.org/junit4/javadoc/latest/org/hamcrest/CoreMatchers.html
Context: junit matcher
Returns: A matcher that match if any of the matchers match the input
Variables: matchers a list/array of matcher

Instruction: any(type)
Page: https://junit.org/junit4/javadoc/latest/org/hamcrest/CoreMatchers.html
Context: junit matcher
Returns: A matcher matching element whose type is type
Variables: matchers a list/array of matcher

Instruction: anything()
Page: https://junit.org/junit4/javadoc/latest/org/hamcrest/CoreMatchers.html
Context: junit matcher
Returns: A matcher always succeeding
Variables: matchers a list/array of matcher

Instruction: anything("foo")
Page: https://junit.org/junit4/javadoc/latest/org/hamcrest/CoreMatchers.html
Context: junit matcher
Returns: A matcher always succeeding and describing itself with foo
Variables: matchers a list/array of matcher

Instruction: both(m1, m2)
Page: https://junit.org/junit4/javadoc/latest/org/hamcrest/CoreMatchers.html
Context: junit matcher
Returns: A matcher matching if both matchers m1 and m2 matches
Variables: matchers a list/array of matcher

Instruction: containsString("foo")
Page: https://junit.org/junit4/javadoc/latest/org/hamcrest/CoreMatchers.html
Context: junit matcher
Returns: A matcher accepting strings containing foo
Variables: matchers a list/array of matcher

Instruction: describedAs(
  "description",
  matcher,
  ...
)
Page: https://junit.org/junit4/javadoc/latest/org/hamcrest/CoreMatchers.html
Context: junit matcher
Returns: A matcher accepting similarly as matcher with "description" as description (  ...) ?
Variables: matchers a list/array of matcher

Instruction: endsWith("suffix")
Page: https://junit.org/junit4/javadoc/latest/org/hamcrest/CoreMatchers.html
Context: junit matcher
Returns: A matcher matching strings ending with suffix

Instruction: equalTo(bar)
Page: https://junit.org/junit4/javadoc/latest/org/hamcrest/CoreMatchers.html
Context: junit matcher
Returns: A matcher for objects `equalTo` bar

Instruction: everyItem(matcher)
Page: https://junit.org/junit4/javadoc/latest/org/hamcrest/CoreMatchers.html
Context: junit matcher
Returns: A matcher matching an iterable whose all elements matches matcher

Instruction: hasItem(matcher)
Page: https://junit.org/junit4/javadoc/latest/org/hamcrest/CoreMatchers.html
Context: junit matcher
Returns: A matcher matching an iterable with an element matching matcher

Instruction: hasItem(matchers)
Page: https://junit.org/junit4/javadoc/latest/org/hamcrest/CoreMatchers.html
Context: junit matcher
Returns: A matcher such that each matcher of matchers satisfies one element of the iterable

Instruction: hasItem(
  item1,
  ...,
  itemn
)
Page: https://junit.org/junit4/javadoc/latest/org/hamcrest/CoreMatchers.html
Context: junit matcher
Returns: A matcher for iterable such that each item is equal to an element of the iterated

Instruction: instanceOf(type)
Page: https://junit.org/junit4/javadoc/latest/org/hamcrest/CoreMatchers.html
Context: junit matcher
Returns: Matches element which are instance of type

Instruction: not(m)
Page: https://junit.org/junit4/javadoc/latest/org/hamcrest/CoreMatchers.html
Context: junit matcher
Returns: A matcher matching elements not matching against m
Variables: m matcher

Instruction: isA(t)
Page: https://junit.org/junit4/javadoc/latest/org/hamcrest/CoreMatchers.html
Context: junit matcher
Returns: is(instanceOf(t))
Variables: T a class

Instruction: is(t)
Page: https://junit.org/junit4/javadoc/latest/org/hamcrest/CoreMatchers.html
Context: junit matcher
Returns: is(equalTo(t))
Variables: T a class

Instruction: is(matcher)
Page: https://junit.org/junit4/javadoc/latest/org/hamcrest/CoreMatchers.html
Context: junit matcher
Returns: same as matcher
Variables: matcher a Matcher
Intuition: to get proper english sentence

Instruction: not(value)
Page: https://junit.org/junit4/javadoc/latest/org/hamcrest/CoreMatchers.html
Context: junit matcher
Returns: not(equalTo(value))

Instruction: notNullValue()
Page: https://junit.org/junit4/javadoc/latest/org/hamcrest/CoreMatchers.html
Context: junit matcher
Returns: not(nullValue())

Instruction: notNullValue(class)
Page: https://junit.org/junit4/javadoc/latest/org/hamcrest/CoreMatchers.html
Context: junit matcher
Returns: not(nullValue(class))

Instruction: nullValue(class)
Page: https://junit.org/junit4/javadoc/latest/org/hamcrest/CoreMatchers.html
Context: junit matcher
Returns: A matcher taking an object of type class and matching if it's null

Instruction: nullValue()
Page: https://junit.org/junit4/javadoc/latest/org/hamcrest/CoreMatchers.html
Context: junit matcher
Returns: A matcher matching against null

Instruction: sameInstance(
  value
)
theInstance(
  value
)
Page: https://junit.org/junit4/javadoc/latest/org/hamcrest/CoreMatchers.html
Context: junit matcher
Returns: A matcher matching things that are same instance as value

Instruction: startsWith(prefix)
Page: https://junit.org/junit4/javadoc/latest/org/hamcrest/CoreMatchers.html
Context: junit matcher
Returns: A matcher matching strings starting with prefix

Instruction: matcher.matches(foo)
Page: https://junit.org/junit4/javadoc/latest/org/hamcrest/CoreMatchers.html
Context: junit matcher
Returns: whether matcher matches foo
Variables: matcher a matcher

Instruction: matcher.describeMismatch(
  foo,
  description
)
Page: https://junit.org/junit4/javadoc/latest/org/hamcrest/CoreMatchers.html
Effect: Generate a description of why the matcher has not accepted the item. The description will be part of a larger description of why a matching failed, so it should be concise. This method assumes that matches(item) is false, but will not check this.
Context: junit matcher
Variables: matcher a matcher

Typ: org.hamcrest.Description
Meaning: A description of a matcher
Page: https://junit.org/junit4/javadoc/latest/org/hamcrest/CoreMatchers.html
Language: java
Context: junit matcher

Instruction: eithelr(m1).or(m2)
Page: https://junit.org/junit4/javadoc/latest/org/hamcrest/CoreMatchers.html
Context: junit matcher
Returns: A matcher matching object satisfying either m1 or m2

Instruction: isThrowable(throwableMatcher)
Page: https://junit.org/junit4/javadoc/latest/org/junit/matchers/JUnitMatchers.html
Context: junit matcher
Returns: A matcher, similar to throwableMatcher, printing also the stacktrace

Instruction: isException(exceptionMatcher)
Page: https://junit.org/junit4/javadoc/latest/org/junit/matchers/JUnitMatchers.html
Context: junit matcher
Returns: A matcher, similar to exceptionMatcher, printing also the stacktrace

Instruction: @Ignore("foo")
Page: https://junit.org/junit4/javadoc/latest/org/junit/matchers/JUnitMatchers.html
Effect: If the test fails, don't consider the run to fail, instead note it's ignored with message foo
Context: junit

Instruction: timeout=foo
Page: https://github.com/junit-team/junit4/wiki/Timeout-for-tests
Effect: Fail if it runs more than foo miliseconds
Context: junit @Test

Instruction: @Rule
public Timeout globalTimeout = t
Page: https://github.com/junit-team/junit4/wiki/Timeout-for-tests
Effect: Each tests, including before and after, runs in at most t time
Context: junit @Test
Variables: t a timeout

Instruction: assumeTrue/assumeThat
Page: https://github.com/junit-team/junit4/wiki/Assumptions-with-assume
Effect: Same than assertTrue/assertThat, but if the assumption match, it is considered as Ignored
Context: junit @Test

Instruction: @Parameters
public static Collection<Object[]> data (){
  return Arrays.asList(new Object[][] {
      {
         {arg_11, ..., arg_1n},
          ...
         {arg_m1, ..., arg_mn},
      }
    }
  );
}
Page: https://github.com/junit-team/junit4/wiki/Parameterized-tests
Effect: The tests is run with objects initalized with
new ClassName(arg_i1, ..., argin);
Context: junit @Test
Assuming: @RunWith(Parameterized.class)

Instruction: @Parameters
public static Collection<Object[]> data (){
  return Arrays.asList(new Object[][] {
      {
         {arg_11, ..., arg_1n},
         P...
         {arg_m1, ..., arg_mn},
      }
    }
  );
}
@Parameter(i)
public type var;
Page: https://github.com/junit-team/junit4/wiki/Parameterized-tests
Effect: The test is run m time, in the j-th run, var has value arg_ji
Context: junit @Test
Assuming: @RunWith(Parameterized.class)

Instruction: @Parameters
public static Object[] data (){
  return new Object[] {arg_1,...,arg_m}
}
@Parameter
public type var;
Page: https://github.com/junit-team/junit4/wiki/Parameterized-tests
Effect: The test is run m time, in the j-th run, var has value arg_j
Context: junit @Test
Assuming: @RunWith(Parameterized.class)

Question: What are the uses of assumption
Answer: If a test is flaky, it shows a warning without stopping CI
Page: https://github.com/junit-team/junit4/wiki/Theories
Context: junit
Answer2: If a test is run on multiple inputs, it allows to ensure stop the tests on inputs not satisfying the assumption

Instruction: @DataPoint
public static type var = value;
Page: https://github.com/junit-team/junit4/wiki/Theories
Effect: The theory tests will be run with input value
Context: junit

Instruction: @Theory
public void testName(vars) {
}
Page: https://github.com/junit-team/junit4/wiki/Theories
Effect: This tests is run once with every values prefixed by `@DatPoint`
Context: junit