Skip to content

Commit d8f25fb

Browse files
authored
Merge pull request #5 from neboskreb/feature/3-junit-extension-for-initialization-of-the-log-config
Feature/3 junit extension for initialization of the log config
2 parents 4b4f19d + 48e76b4 commit d8f25fb

File tree

6 files changed

+39
-18
lines changed

6 files changed

+39
-18
lines changed

examples/app/build.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff 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"

examples/app/src/androidTest/java/com/github/neboskreb/log4j2/examples/app/GreatManagerAndroidTest.java

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,12 @@
11
package com.github.neboskreb.log4j2.examples.app;
22

3-
import androidx.test.platform.app.InstrumentationRegistry;
43
import 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;
75
import org.junit.jupiter.api.Test;
6+
import org.junit.jupiter.api.extension.ExtendWith;
87

8+
@ExtendWith(AndroidLog4jExtension.class)
99
public class GreatManagerAndroidTest {
10-
@BeforeAll
11-
public static void beforeAll() {
12-
AndroidLog4jHelper.initialize(InstrumentationRegistry.getInstrumentation());
13-
}
14-
1510

1611
@Test
1712
public void onLogFatalMessageClicked() {

examples/lib/build.gradle

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff 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'

examples/lib/src/androidTest/java/com/github/neboskreb/log4j2/examples/lib/AwesomeWorkerAndroidTest.java

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,13 @@
11
package 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;
64
import 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)
1010
public class AwesomeWorkerAndroidTest {
11-
@BeforeAll
12-
static void beforeAll() {
13-
AndroidLog4jHelper.initialize(InstrumentationRegistry.getInstrumentation());
14-
}
15-
1611

1712
@Test
1813
public void doGreatJob() {

library/build.gradle

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff 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'
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
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+
}

0 commit comments

Comments
 (0)