Skip to content

Commit 47514d6

Browse files
committed
Further fix README
Remove Logging, because I'd rather use System.out than deal with that damn libraries and configuration
1 parent 7209b0e commit 47514d6

File tree

6 files changed

+58
-77
lines changed

6 files changed

+58
-77
lines changed

README.adoc

Lines changed: 39 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -22,16 +22,12 @@ It introduced a lot of interesting, fast ways to create tests.
2222
Be it Test-Factories, Test-Extensions (that only have to be implemented once), Lambda-Support etc.
2323
It pushes the D.R.Y. principle a lot!
2424

25-
To understand this guide you should know the basics of testing and JUnit (4), but otherwise you wouldn't be here I guess.
25+
To follow this guide you should know the basics of testing and JUnit (4), but otherwise you wouldn't be here I guess.
2626
You can also check out the best-practice-part included in this repository.
2727
It was created by request of a colleague:
2828
link:src/test/java/com/drandarov/bestPractice/JUnit_BestPractice.java[**Checkout JUnit best-practices included in this repository**]
2929

30-
JUnit 5 also supports running parallel to JUnit 4 if that's something you need.
31-
3230
Some headers related to code will have a code-link behind their name directing to the corresponding class in the GitHub-Repository.
33-
For the whole source code see my GitHub-Repository:
34-
https://github.com/dmitrij-drandarov/JUnit5-Quick-Start-Guide-and-Advanced[**dmitrij-drandarov/JUnit5-Quick-Start-Guide-and-Advanced**]
3531

3632
=== Setup
3733
For an IDE I recommend *IntelliJ IDEA 2016.2(+)* right now since it brings native support for JUnit 5.
@@ -152,7 +148,7 @@ void assumptionsTest() {
152148

153149
== New features: Basics link:src/test/java/com/drandarov/junit5/JUnit5_01_NewFeaturesBasics.java[(code)]
154150

155-
### General
151+
=== General
156152
Here I want to introduce some basics for the new features available in the new version.
157153
There is a new pretty annotation called `@DisplayName` which is supposed to improve the readability of test reports, so you don't need 40-character test-names to make clear what the test is about at a glance.
158154

@@ -187,7 +183,7 @@ class groupedTests {
187183

188184
image::02_nestedTests_result.png[]
189185

190-
### Assertions and Lambda-Support
186+
=== Assertions and Lambda-Support
191187
Now for the probably most known and anticipated feature in JUnit 5: Lambda-Support...
192188
JUnit 5 `Assertions` and `Assumptions` classes and its methods now provide Lambda support.
193189
This is achieved by providing methods with functional interfaces as parameters.
@@ -264,7 +260,7 @@ void expectThrowsTest() {
264260
}
265261
```
266262

267-
### Parameter Resolver
263+
=== Parameter Resolver
268264

269265
The biggest new feature in JUnit 5 is the new Extension-API.
270266
A part of it is the `ParameterResolver`-Interface which is an extension of the `Extension`-Interface itself.
@@ -299,7 +295,7 @@ void parameterTest(TestInfo testInfo, TestReporter testReporter) {
299295

300296
== New features: Advanced link:src/test/java/com/drandarov/junit5/JUnit5_02_NewFeaturesAdvanced.java[(code)]
301297

302-
### Test-Parameters
298+
=== Test-Parameters
303299
Building upon the `ParameterResolver` paragraph of the last chapter let's look at implementing your own `ParameterResolver`.
304300
You can also see the first visual sign of the Extension-API in the form of the `@ExtendWith`-Annotation. The final result is:
305301

@@ -384,7 +380,7 @@ public class ParameterIndex_ParameterResolver implements ParameterResolver {
384380
}
385381
```
386382

387-
### Test-Factories
383+
=== Test-Factories
388384
Another nice feature are the new Test-Factories.
389385
These are annotated with `@TestFactory` instead of `@Test`.
390386
Their return type is some kind of collection of ``DynamicTest``s.
@@ -415,7 +411,7 @@ Stream<DynamicTest> testStreamFactoryTest() {
415411

416412
image::03_testFactory_result.png[]
417413

418-
### Test-Extensions
414+
=== Test-Extensions
419415
Here I will show you an `Extension` that is not based on the `ParameterResolver` but instead implements the `TestExecutionCondition`.
420416
The same thing that powers the `@Disabled` annotation.
421417
If we want to customize it we need out own implementation.
@@ -465,9 +461,9 @@ void disabledOnMondayTest() {}
465461
Again: This could without problem be placed on class-level.
466462

467463

468-
== Advanced Test-Samples link:src/test/java/com/drandarov/junit5/JUnit5_00_GeneralChanges.java[(code)]
464+
== Advanced Test-Samples link:src/test/java/com/drandarov/junit5/JUnit5_03_AdvancedTestSamples.java[(code)]
469465

470-
### Extended disabled weekdays
466+
=== Extended disabled weekdays
471467
Let's extend that `@DisabledOnMonday` annotation a bit.
472468
What if you want to choose the weekday?
473469
Creating 7 annotations is kind of overkill.
@@ -541,7 +537,7 @@ public class DisabledOnWeekday implements TestExecutionCondition {
541537
}
542538
```
543539

544-
### Extend Test-Annotation
540+
=== Extend Test-Annotation
545541
So what if you want to save some that space occupied by all those annotations.
546542
Let's make it all-in-one for this example:
547543

@@ -598,7 +594,7 @@ One extension resolves the `Pane` from the fxml path and the other one just prin
598594
This is rather a showcase of an `@Test`-Extension and including utilizing the extension features of JUnit 5.
599595
If you want to see code nevertheless look into the repository.
600596

601-
### Benchmarking Example
597+
=== Benchmarking Example
602598

603599
As for the last example right now I will showcase some benchmarking possibilities and it isn't even that complicated.
604600
There are several extensions that can be used for that.
@@ -699,44 +695,44 @@ Of course I could have also included `@Benchmarked` in a separate `@BenchmarkedT
699695

700696
== Changes from M4-RC2 link:src/test/java/com/drandarov/junit5/xxxxxxxxxxx.java[(code)]
701697

702-
### TODO
698+
=== TODO
703699
.
704700

705701
== Closing words
706702

707-
### Contribution
703+
=== Contribution
708704
Feel free to express critique and contribute to the [repository](https://github.com/dmitrij-drandarov/JUnit5-Quick-Start-Guide-and-Advanced) :)
709705

710-
### Usage
706+
=== Usage
711707
You can use this repository in any way you want.
712708
May it be for workshops or presentations. Just give credits. ;)
713709

714-
### Schedule
715-
- [ ] 5.0 GA (General Availability Release) Update - Due by August 24, 2017
710+
=== Schedule
711+
* [ ] 5.0 GA (General Availability Release) Update - Due by August 24, 2017
716712

717-
### Further Reference
718-
[Official JUnit 5 User Guide](http://junit.org/junit5/docs/current/user-guide)
719-
[JUnit 5 GitHub](https://github.com/junit-team/junit5)
720-
[JUnit 5 Milestone plan](https://github.com/junit-team/junit5/milestones/)
713+
=== Further Reference
714+
[%hardbreaks]
715+
* http://junit.org/junit5/docs/current/user-guide[Official JUnit 5 User Guide]
716+
* https://github.com/junit-team/junit5[JUnit 5 GitHub]
717+
* https://github.com/junit-team/junit5/milestones/[JUnit 5 Milestone plan]
721718

722719
== Repository Timeline
723720

724-
[%interactive]
725-
- [ ] Update for M4-RC2 - XX Aug 2017
726-
- [x] Fix userInterfaceTest - 01 Aug 2017
727-
- [x] Create wiki article with githup-pages-content - 04 Mar 2017
728-
- [x] Convert code fragments from images to text - 04 Mar 2017
729-
- [x] Incorporate JUnit Best-Practice on request - 15 Feb 2017
730-
- [x] Change name - 05 Aug 2016
731-
- [x] Finish Stream TODOs - 05 Aug 2016
732-
- [x] Proper Presentation - 04 Aug 2016
733-
- [x] Add reference - 03 Aug 2016
734-
- [x] Add expectThrows() - 03 Aug 2016
735-
- [x] Add @Nested - 03 Aug 2016
736-
- [x] Adjust packages and classes for presentation - 01 Aug 2016
737-
- [x] Extend Test-Extensions - 29 Jul 2016
738-
- [x] Test-Extensions (o\j\j\api\extension) - 28 Jul 2016
739-
- [x] @TestFactory + DynamicTests - 26 Jul 2016
740-
- [x] Reorder packages and classes - 26 Jul 2016
741-
- [x] Links to Java-Files - 24 Jul 2016
742-
- [x] Dependency Copy-Paste Resource - 24 Jul 2016
721+
* [ ] Update for M4-RC2 - XX Aug 2017
722+
* [x] Fix userInterfaceTest - 01 Aug 2017
723+
* [x] Create wiki article with githup-pages-content - 04 Mar 2017
724+
* [x] Convert code fragments from images to text - 04 Mar 2017
725+
* [x] Incorporate JUnit Best-Practice on request - 15 Feb 2017
726+
* [x] Change name - 05 Aug 2016
727+
* [x] Finish Stream TODOs - 05 Aug 2016
728+
* [x] Proper Presentation - 04 Aug 2016
729+
* [x] Add reference - 03 Aug 2016
730+
* [x] Add expectThrows() - 03 Aug 2016
731+
* [x] Add @Nested - 03 Aug 2016
732+
* [x] Adjust packages and classes for presentation - 01 Aug 2016
733+
* [x] Extend Test-Extensions - 29 Jul 2016
734+
* [x] Test-Extensions (o\j\j\api\extension) - 28 Jul 2016
735+
* [x] @TestFactory + DynamicTests - 26 Jul 2016
736+
* [x] Reorder packages and classes - 26 Jul 2016
737+
* [x] Links to Java-Files - 24 Jul 2016
738+
* [x] Dependency Copy-Paste Resource - 24 Jul 2016

src/test/java/com/drandarov/junit5/JUnit5_01_NewFeaturesBasics.java

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@
88

99
import java.util.function.BooleanSupplier;
1010
import java.util.function.Supplier;
11-
import java.util.logging.Logger;
1211

1312
import static org.junit.jupiter.api.Assertions.*;
1413

@@ -20,8 +19,6 @@
2019
*/
2120
class JUnit5_01_NewFeaturesBasics {
2221

23-
private static final Logger LOG = Logger.getGlobal();
24-
2522
/*##############################################
2623
# Test-Methods
2724
##############################################*/
@@ -140,10 +137,10 @@ void assumptionsLambdaTest() {
140137
*/
141138
@Test
142139
void parameterTest(TestInfo testInfo, TestReporter testReporter) {
143-
LOG.info("DisplayName:\t" + testInfo.getDisplayName());
144-
LOG.info("Tags:\t\t\t" + testInfo.getTags());
145-
LOG.info("TestClass:\t\t" + testInfo.getTestClass());
146-
LOG.info("TestMethod:\t\t" + testInfo.getTestMethod());
140+
System.out.println("DisplayName:\t" + testInfo.getDisplayName());
141+
System.out.println("Tags:\t\t\t" + testInfo.getTags());
142+
System.out.println("TestClass:\t\t" + testInfo.getTestClass());
143+
System.out.println("TestMethod:\t\t" + testInfo.getTestMethod());
147144

148145
testReporter.publishEntry("parameterTestTime", String.valueOf(System.currentTimeMillis()));
149146
}

src/test/java/com/drandarov/junit5/JUnit5_02_NewFeaturesAdvanced.java

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@
1313
import java.util.Arrays;
1414
import java.util.Iterator;
1515
import java.util.function.Function;
16-
import java.util.logging.Logger;
1716
import java.util.stream.Stream;
1817

1918
/**
@@ -24,8 +23,6 @@
2423
*/
2524
class JUnit5_02_NewFeaturesAdvanced {
2625

27-
private static final Logger LOG = Logger.getGlobal();
28-
2926
/*##############################################
3027
# Test-Parameters
3128
##############################################*/
@@ -41,8 +38,8 @@ class JUnit5_02_NewFeaturesAdvanced {
4138
@Test
4239
@ExtendWith({ClassName_ParameterResolver.class, ParameterIndex_ParameterResolver.class})
4340
void customParameterTest(String className, Long parameterIndex) {
44-
LOG.info(className); // Surrounding class name injected by ClassName_ParameterResolver
45-
LOG.info(parameterIndex.toString()); // Parameter-Index injected by ParameterIndex_ParameterResolver
41+
System.out.println(className); // Surrounding class name injected by ClassName_ParameterResolver
42+
System.out.println(parameterIndex.toString()); // Parameter-Index injected by ParameterIndex_ParameterResolver
4643
}
4744

4845

src/test/java/com/drandarov/junit5/JUnit5_03_AdvancedTestSamples.java

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@
1212
import java.util.ArrayList;
1313
import java.util.Calendar;
1414
import java.util.List;
15-
import java.util.logging.Logger;
1615
import java.util.stream.IntStream;
1716
import java.util.stream.LongStream;
1817

@@ -24,8 +23,6 @@
2423
*/
2524
class JUnit5_03_AdvancedTestSamples {
2625

27-
private static final Logger LOG = Logger.getGlobal();
28-
2926
/*##############################################
3027
# Advanced Test-Samples
3128
##############################################*/
@@ -51,8 +48,8 @@ void disabledOnWeekdaysTest() {}
5148
*/
5249
@UITest("../../sample.fxml")
5350
void userInterfaceTest(Pane root) {
54-
LOG.info(String.valueOf(root.getPrefWidth())); // 555.0 (defined in FXML-File)
55-
LOG.info(String.valueOf(root.getPrefHeight())); // 333.0 (defined in FXML-File)
51+
System.out.println(String.valueOf(root.getPrefWidth())); // 555.0 (defined in FXML-File)
52+
System.out.println(String.valueOf(root.getPrefHeight())); // 333.0 (defined in FXML-File)
5653
}
5754

5855
/**
@@ -66,7 +63,7 @@ void userInterfaceTest(Pane root) {
6663
@Benchmarked
6764
void benchmarkedTest() {
6865
List<Integer> primes = new ArrayList<>();
69-
LOG.info("Calculating some primes...");
66+
System.out.println("Calculating some primes...");
7067
IntStream.iterate(2, i -> i + 1)
7168
.filter(i -> LongStream.rangeClosed(2, (long)(Math.sqrt(i))).allMatch(n -> i % n != 0))
7269
.limit(55555)

src/test/java/com/drandarov/junit5/utils/benchmarked/BenchmarkExtension.java

Lines changed: 9 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66
import java.text.DateFormat;
77
import java.util.HashMap;
88
import java.util.Map;
9-
import java.util.logging.Logger;
109

1110
import static java.lang.System.currentTimeMillis;
1211

@@ -24,15 +23,13 @@ public class BenchmarkExtension implements BeforeAllCallback, BeforeTestExecutio
2423
private static final Map<String, Long> startTime = new HashMap<>();
2524
private static final DateFormat dtForm = DateFormat.getDateTimeInstance(DateFormat.SHORT, DateFormat.MEDIUM);
2625

27-
private static final Logger LOG = Logger.getGlobal();
28-
2926
@Override
3027
public void beforeAll(ExtensionContext context) throws Exception {
3128
String disp = context.getDisplayName();
3229
long start = currentTimeMillis();
3330

34-
LOG.info("#### Summary \t" + APD + disp + " ####");
35-
LOG.info("#### Start of Benchmark\t" + APD + disp + APD + dtForm.format(new Date(start)) + " ####");
31+
System.out.println("#### Summary \t" + APD + disp + " ####");
32+
System.out.println("#### Start of Benchmark\t" + APD + disp + APD + dtForm.format(new Date(start)) + " ####");
3633
startTime.put(disp, start);
3734
}
3835

@@ -41,7 +38,7 @@ public void beforeTestExecution(ExtensionContext context) throws Exception {
4138
String disp = context.getDisplayName();
4239
long start = currentTimeMillis();
4340

44-
LOG.info("#### Method-Benchm. ####" + APD + disp + APD + dtForm.format(new Date(start)));
41+
System.out.println("#### Method-Benchm. ####" + APD + disp + APD + dtForm.format(new Date(start)));
4542
startTime.put(context.getDisplayName(), start);
4643
}
4744

@@ -50,19 +47,19 @@ public void afterTestExecution(ExtensionContext context) throws Exception {
5047
String disp = context.getDisplayName();
5148
long end = currentTimeMillis();
5249

53-
LOG.info("#### Summary ####" + APD + disp);
54-
LOG.info("#### Start ####" + APD + dtForm.format(new Date(startTime.get(disp))));
55-
LOG.info("#### End ####" + APD + dtForm.format(new Date(end)));
56-
LOG.info("#### Duration ####" + APD + (end - startTime.get(disp)) + " ms\n");
50+
System.out.println("#### Summary ####" + APD + disp);
51+
System.out.println("#### Start ####" + APD + dtForm.format(new Date(startTime.get(disp))));
52+
System.out.println("#### End ####" + APD + dtForm.format(new Date(end)));
53+
System.out.println("#### Duration ####" + APD + (end - startTime.get(disp)) + " ms\n");
5754
}
5855

5956
@Override
6057
public void afterAll(ExtensionContext context) throws Exception {
6158
String disp = context.getDisplayName();
6259
long end = currentTimeMillis();
6360

64-
LOG.info("#### End of Benchmark \t" + APD + disp + APD + dtForm.format(new Date(end)) + " ####");
65-
LOG.info("#### Duration for class\t" + APD + disp + APD + (end - startTime.get(disp)) + " ms ####");
61+
System.out.println("#### End of Benchmark \t" + APD + disp + APD + dtForm.format(new Date(end)) + " ####");
62+
System.out.println("#### Duration for class\t" + APD + disp + APD + (end - startTime.get(disp)) + " ms ####");
6663
}
6764

6865
}

src/test/java/com/drandarov/junit5/utils/testannotationextension/PrintUITestData.java

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55

66
import java.lang.reflect.AnnotatedElement;
77
import java.util.Optional;
8-
import java.util.logging.Logger;
98

109
/**
1110
* Prints some information about the Test annotated by @{@link UITest}.
@@ -15,16 +14,14 @@
1514
*/
1615
class PrintUITestData implements BeforeEachCallback {
1716

18-
private static final Logger LOG = Logger.getGlobal();
19-
2017
@Override
2118
public void beforeEach(ExtensionContext context) throws Exception {
2219
Optional<AnnotatedElement> contextElement = context.getElement();
2320
AnnotatedElement annotatedElement = contextElement.orElse(null);
2421

2522
if (annotatedElement != null) {
2623
UITest uiTest = annotatedElement.getAnnotation(UITest.class);
27-
LOG.info("Doing some setup for " + uiTest.value());
24+
System.out.println("Doing some setup for " + uiTest.value());
2825
}
2926

3027
}

0 commit comments

Comments
 (0)