File tree Expand file tree Collapse file tree 9 files changed +80
-4
lines changed 
jvmTest/kotlin/test/assertk Expand file tree Collapse file tree 9 files changed +80
-4
lines changed Original file line number Diff line number Diff line change @@ -23,6 +23,14 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.
2323
2424### Added  
2525-  Added ` doesNotContainKey `  assertion for ` Map ` 
26+ -  Added ` assume `  to support test assumptions. To use, wrap your assertions
27+   ``` kotlin 
28+   assume {
29+     assertThat(System .getProperty(" os.name" " Windows" 
30+   }
31+   ``` 
32+   this will cause the test to be skipped instead of failing.
33+   Note: This feature only works with opentest4j-compatible testing frameworks like junit5.
2634
2735### Fixed  
2836-  Fixed incorrect usage of contains in some kdoc examples
Original file line number Diff line number Diff line change @@ -64,3 +64,7 @@ kotlin {
6464        }
6565    }
6666}
67+ 
68+ tasks.withType<Test >().configureEach {
69+     useJUnitPlatform()
70+ }
Original file line number Diff line number Diff line change 1+ package  assertk 
2+ 
3+ /* *
4+  * Aborts the test instead of failing it, this gives you a way to skip tests based on a dynamic assertion. 
5+  * 
6+  * ``` 
7+  * // only run test on windows 
8+  * assume { 
9+  *     assertThat(System.getProperty("os.name")).startsWith("Windows") 
10+  * } 
11+  * ``` 
12+  */  
13+ fun  assume (f :  () ->  Unit ) {
14+     AssumptionFailure .run  { f() }
15+ }
Original file line number Diff line number Diff line change 33
44package  assertk 
55
6+ import  com.willowtreeapps.opentest4k.AssertionFailedError 
7+ import  com.willowtreeapps.opentest4k.TestAbortedException 
8+ 
69internal  actual  inline  fun  failWithNotInStacktrace (error :  Throwable ): Nothing  {
710    val  filtered =  error.stackTrace
811        .dropWhile { it.className.startsWith(" assertk" 
@@ -16,3 +19,21 @@ internal actual inline fun failWithNotInStacktrace(error: Throwable): Nothing {
1619internal  actual  inline  fun  Throwable.isFatal (): Boolean  = 
1720    //  https://github.com/ReactiveX/RxJava/blob/6a44e5d0543a48f1c378dc833a155f3f71333bc2/src/main/java/io/reactivex/exceptions/Exceptions.java#L66
1821    this  is  VirtualMachineError  ||  this  is  ThreadDeath  ||  this  is  LinkageError 
22+ 
23+ internal  object  AssumptionFailure : Failure {
24+     override  fun  fail (error :  Throwable ) {
25+         failWithNotInStacktrace(
26+             TestAbortedException (
27+                 buildString {
28+                     append(" Assumption failed" 
29+                     error.message?.let  { message -> 
30+                         append(" : " 
31+                         append(message)
32+                     }
33+                 },
34+                 //  unwrap assertion errors
35+                 if  (error is  AssertionFailedError ) error.cause else  error
36+             )
37+         )
38+     }
39+ }
Original file line number Diff line number Diff line change @@ -4,9 +4,9 @@ import assertk.all
44import  assertk.assertAll 
55import  assertk.assertThat 
66import  assertk.assertions.* 
7- import  org.junit.Test 
87import  java.util.concurrent.Executors 
98import  java.util.concurrent.TimeUnit 
9+ import  kotlin.test.Test 
1010import  kotlin.test.assertEquals 
1111import  kotlin.test.assertFailsWith 
1212import  kotlin.test.assertFalse 
Original file line number Diff line number Diff line change 1+ package  test.assertk.assertions 
2+ 
3+ import  assertk.assertThat 
4+ import  assertk.assertions.isFalse 
5+ import  assertk.assume 
6+ import  com.willowtreeapps.opentest4k.TestAbortedException 
7+ import  kotlin.test.Test 
8+ import  kotlin.test.assertEquals 
9+ import  kotlin.test.assertFailsWith 
10+ 
11+ class  AssumeTest  {
12+     @Test
13+     fun  assume_throws_TestAbortedException () {
14+         val  error =  assertFailsWith<TestAbortedException > {
15+             assume {
16+                 assertThat(true ).isFalse()
17+             }
18+         }
19+ 
20+         assertEquals(" Assumption failed: expected to be false" 
21+     }
22+ 
23+     @Test
24+     fun  assume_aborts_instead_of_fails_test () {
25+         //  this test should be skipped instead of failing
26+         assume { assertThat(true ).isFalse() }
27+     }
28+ }
Original file line number Diff line number Diff line change @@ -2,8 +2,8 @@ package test.assertk.assertions
22
33import  assertk.assertThat 
44import  assertk.assertions.isSuccess 
5- import  org.junit.Test 
65import  test.assertk.exceptionPackageName 
6+ import  kotlin.test.Test 
77import  kotlin.test.assertEquals 
88import  kotlin.test.assertFailsWith 
99import  kotlin.test.assertNotNull 
Original file line number Diff line number Diff line change @@ -4,10 +4,10 @@ import assertk.all
44import  assertk.assertAll 
55import  assertk.assertThat 
66import  assertk.assertions.* 
7- import  org.junit.Test 
87import  java.time.LocalDate 
98import  java.time.Month 
109import  java.util.* 
10+ import  kotlin.test.Test 
1111import  kotlin.test.assertEquals 
1212import  kotlin.test.assertFailsWith 
1313
Original file line number Diff line number Diff line change @@ -4,9 +4,9 @@ import assertk.assertThat
44import  assertk.assertions.isNegative 
55import  assertk.assertions.isPositive 
66import  assertk.assertions.isZero 
7- import  org.junit.Test 
87import  java.math.BigDecimal 
98import  java.math.BigInteger 
9+ import  kotlin.test.Test 
1010import  kotlin.test.assertEquals 
1111import  kotlin.test.assertFailsWith 
1212
 
 
   
 
     
   
   
          
    
    
     
    
      
     
     
    You can’t perform that action at this time.
  
 
    
  
    
      
        
     
       
      
     
   
 
    
    
  
 
  
 
     
    
0 commit comments