File tree Expand file tree Collapse file tree 6 files changed +39
-18
lines changed
src/androidTest/java/com/github/neboskreb/log4j2/examples/app
src/androidTest/java/com/github/neboskreb/log4j2/examples/lib
src/testFixtures/java/net/loune/log4j2android Expand file tree Collapse file tree 6 files changed +39
-18
lines changed Original file line number Diff line number Diff line change @@ -60,7 +60,7 @@ dependencies {
6060 testImplementation ' org.junit.jupiter:junit-jupiter'
6161 testImplementation ' org.junit.platform:junit-platform-launcher'
6262
63-
63+ androidTestImplementation testFixtures(project( " :library " ))
6464 androidTestImplementation ' androidx.test.ext:junit:1.2.1'
6565 androidTestImplementation platform(' org.junit:junit-bom:5.12.2' )
6666 androidTestImplementation " org.junit.jupiter:junit-jupiter-api"
Original file line number Diff line number Diff line change 11package com .github .neboskreb .log4j2 .examples .app ;
22
3- import androidx .test .platform .app .InstrumentationRegistry ;
43import com .github .neboskreb .log4j2 .examples .lib .AwesomeWorker ;
5- import net .loune .log4j2android .AndroidLog4jHelper ;
6- import org .junit .jupiter .api .BeforeAll ;
4+ import net .loune .log4j2android .AndroidLog4jExtension ;
75import org .junit .jupiter .api .Test ;
6+ import org .junit .jupiter .api .extension .ExtendWith ;
87
8+ @ ExtendWith (AndroidLog4jExtension .class )
99public class GreatManagerAndroidTest {
10- @ BeforeAll
11- public static void beforeAll () {
12- AndroidLog4jHelper .initialize (InstrumentationRegistry .getInstrumentation ());
13- }
14-
1510
1611 @ Test
1712 public void onLogFatalMessageClicked () {
Original file line number Diff line number Diff line change @@ -50,6 +50,7 @@ dependencies {
5050
5151
5252 androidTestImplementation(project(" :library" ))
53+ androidTestImplementation testFixtures(project(" :library" ))
5354 androidTestImplementation ' androidx.test:core:1.6.1'
5455 androidTestImplementation ' androidx.test:runner:1.6.2'
5556 androidTestImplementation ' androidx.test.ext:junit:1.2.1'
Original file line number Diff line number Diff line change 11package com .github .neboskreb .log4j2 .examples .lib ;
22
3- import androidx .test .platform .app .InstrumentationRegistry ;
4- import net .loune .log4j2android .AndroidLog4jHelper ;
5- import org .junit .jupiter .api .BeforeAll ;
3+ import net .loune .log4j2android .AndroidLog4jExtension ;
64import org .junit .jupiter .api .Test ;
5+ import org .junit .jupiter .api .extension .ExtendWith ;
76
8- import static org .junit .jupiter .api .Assertions .* ;
7+ import static org .junit .jupiter .api .Assertions .assertEquals ;
98
9+ @ ExtendWith (AndroidLog4jExtension .class )
1010public class AwesomeWorkerAndroidTest {
11- @ BeforeAll
12- static void beforeAll () {
13- AndroidLog4jHelper .initialize (InstrumentationRegistry .getInstrumentation ());
14- }
15-
1611
1712 @ Test
1813 public void doGreatJob () {
Original file line number Diff line number Diff line change @@ -47,6 +47,10 @@ android {
4747 }
4848 }
4949
50+ testFixtures {
51+ enable = true
52+ }
53+
5054 compileOptions {
5155 sourceCompatibility JavaVersion . VERSION_11
5256 targetCompatibility JavaVersion . VERSION_11
@@ -82,6 +86,15 @@ dependencies {
8286 // ==== /Lombok
8387
8488
89+ testFixturesImplementation ' androidx.test.ext:junit:1.2.1'
90+ testFixturesImplementation ' androidx.annotation:annotation:1.9.1'
91+ testFixturesImplementation ' com.google.code.findbugs:jsr305:3.0.2'
92+ testFixturesImplementation platform(' org.junit:junit-bom:5.12.2' )
93+ testFixturesImplementation ' org.junit.jupiter:junit-jupiter-api'
94+ testFixturesImplementation ' org.junit.jupiter:junit-jupiter'
95+ testFixturesRuntimeOnly ' org.junit.platform:junit-platform-launcher'
96+
97+
8598 testImplementation platform(' org.junit:junit-bom:5.12.2' )
8699 testImplementation ' org.junit.jupiter:junit-jupiter-api'
87100 testImplementation ' org.junit.jupiter:junit-jupiter'
Original file line number Diff line number Diff line change 1+ package net .loune .log4j2android ;
2+
3+ import androidx .test .platform .app .InstrumentationRegistry ;
4+ import org .junit .jupiter .api .extension .BeforeAllCallback ;
5+ import org .junit .jupiter .api .extension .ExtensionContext ;
6+
7+ public class AndroidLog4jExtension implements BeforeAllCallback {
8+ private static boolean isInitialized ;
9+
10+ @ Override
11+ public void beforeAll (ExtensionContext context ) throws Exception {
12+ if (!isInitialized ) {
13+ isInitialized = true ;
14+ AndroidLog4jHelper .initialize (InstrumentationRegistry .getInstrumentation ());
15+ }
16+ }
17+ }
You can’t perform that action at this time.
0 commit comments