Skip to content

Instantly share code, notes, and snippets.

@kittinunf
Created October 23, 2016 07:12
Show Gist options
  • Save kittinunf/8f1ec14ae9319a46fdf048c6add135d0 to your computer and use it in GitHub Desktop.
Save kittinunf/8f1ec14ae9319a46fdf048c6add135d0 to your computer and use it in GitHub Desktop.
class MyTestClass {
companion object {
init {
// things that may need to be setup before companion class member variables are instantiated
}
// variables you initialize for the class just once:
val someClassVar = initializer()
// variables you initialize for the class later in the @BeforeClass method:
lateinit var someClassLateVar: SomeResource
@BeforeClass @JvmStatic fun setup() {
// things to execute once and keep around for the class
}
@AfterClass @JvmStatic fun teardown() {
// clean up after this class, leave nothing dirty behind
}
}
// variables you initialize per instance of the test class:
val someInstanceVar = initializer()
// variables you initialize per test case later in your @Before methods:
var lateinit someInstanceLateZVar: MyType
@Before fun prepareTest() {
// things to do before each test
}
@After fun cleanupTest() {
// things to do after each test
}
@Test fun testSomething() {
// an actual test case
}
@Test fun testSomethingElse() {
// another test case
}
// ...more test cases
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment