@@ -2,6 +2,7 @@ package net.mullvad.mullvadvpn.test.arch
2
2
3
3
import com.lemonappdev.konsist.api.Konsist
4
4
import com.lemonappdev.konsist.api.verify.assertEmpty
5
+ import com.lemonappdev.konsist.api.verify.assertTrue
5
6
import org.junit.jupiter.api.Test
6
7
7
8
class JUnitTest {
@@ -27,4 +28,38 @@ class JUnitTest {
27
28
}
28
29
}
29
30
.assertEmpty()
31
+
32
+ @Test
33
+ fun `ensure all non android tests are written with spaces` () =
34
+ allNonAndroidTests().assertTrue { it.name.contains(' ' ) }
35
+
36
+ @Test
37
+ fun `ensure all non android tests does start with lower case letter` () =
38
+ allNonAndroidTests().assertTrue { it.name.first().isLowerCase() }
39
+
40
+ @Test
41
+ fun `ensure all non android tests have 'ensure' or 'should' in function name` () =
42
+ allNonAndroidTests().assertTrue { it.name.containsEnsureOrShould() }
43
+
44
+ private fun String.containsEnsureOrShould (): Boolean {
45
+ return contains(" ensure" ) || contains(" should" ) || contains(" then" )
46
+ }
47
+
48
+ private fun allNonAndroidTests () =
49
+ Konsist .scopeFromTest()
50
+ .functions()
51
+ // withAnnotationOf is broken in latest Consist version, so we filter manually
52
+ // https://github.com/LemonAppDev/konsist/discussions/738
53
+ .filter { it.annotations.any { it.text == " @Test" } }
54
+ .filter { it.sourceSetName != " androidTest" }
55
+ .filter { function ->
56
+ ignoredTestPackages.none { function.packagee!! .fullyQualifiedName.startsWith(it) }
57
+ }
58
+
59
+ companion object {
60
+ // The following packages are not following the naming convention since they are android
61
+ // test that does not support spaces in function names.
62
+ private val ignoredTestPackages =
63
+ listOf (" net.mullvad.mullvadvpn.test.e2e" , " net.mullvad.mullvadvpn.test.mockapi" )
64
+ }
30
65
}
0 commit comments