1

00:00:00.06 --> 00:00:03.02

- [Instructor] A big part of

the Spring 5.0 improvements



2

00:00:03.02 --> 00:00:04.09

come around the testing,



3

00:00:04.09 --> 00:00:08.09

specifically around the

utilization of JUnit 5 Jupiter.



4

00:00:08.09 --> 00:00:09.08

With Spring 5,



5

00:00:09.08 --> 00:00:12.04

the JUnit 5 or JUnit Jupiter



6

00:00:12.04 --> 00:00:15.04

brings both programming

and extension models,



7

00:00:15.04 --> 00:00:20.02

and we get all of that support

within Spring Test context.



8

00:00:20.02 --> 00:00:23.06

The @RunWith annotation is

no longer really supported.



9

00:00:23.06 --> 00:00:27.03

Instead we're now going with

the @ExtendsWith annotation.



10

00:00:27.03 --> 00:00:29.02

And as such, there is a new class.



11

00:00:29.02 --> 00:00:30.08

Instead of the JUnit 4 runner,



12

00:00:30.08 --> 00:00:34.04

there is now a SpringExtension.class.



13

00:00:34.04 --> 00:00:37.03

Now, this provides full

support for TestContext



14

00:00:37.03 --> 00:00:39.09

and all of its previous feature set.



15

00:00:39.09 --> 00:00:42.04

We've also had several

annotations that were added



16

00:00:42.04 --> 00:00:44.08

to make your life just

a little bit easier.



17

00:00:44.08 --> 00:00:47.03

The first is the SpringJUnitConfig,



18

00:00:47.03 --> 00:00:51.01

and really this is just a

composition of two annotations,



19

00:00:51.01 --> 00:00:53.08

the @ExtendWith for SpringExtension class,



20

00:00:53.08 --> 00:00:55.08

and that's the Jupiter component,



21

00:00:55.08 --> 00:00:57.04

and the @ContextConfiguration,



22

00:00:57.04 --> 00:00:59.02

and that was the Spring component



23

00:00:59.02 --> 00:01:02.04

that allowed you to specify

your application context



24

00:01:02.04 --> 00:01:04.03

that you wanted to be loaded



25

00:01:04.03 --> 00:01:07.02

during the running of your JUnit test.



26

00:01:07.02 --> 00:01:08.07

Now, this gives us the

ability to configure



27

00:01:08.07 --> 00:01:10.09

the application context within JUnit



28

00:01:10.09 --> 00:01:13.07

and let it all be run with the ExtendWith



29

00:01:13.07 --> 00:01:15.05

SpringExtension class.



30

00:01:15.05 --> 00:01:19.00

So we get all of that with

just one simple annotation.



31

00:01:19.00 --> 00:01:21.08

And it gets a little bit

better in the web role,



32

00:01:21.08 --> 00:01:24.04

where now we have a

composition of three parts.



33

00:01:24.04 --> 00:01:26.08

So we get both of the parts

from SpringJUnitConfig



34

00:01:26.08 --> 00:01:28.09

that we just solved.



35

00:01:28.09 --> 00:01:33.01

In addition, we get the

WebApplicationContext annotation.



36

00:01:33.01 --> 00:01:36.06

Now, this provides a servlet

context to our tests,



37

00:01:36.06 --> 00:01:37.09

which can be very valuable



38

00:01:37.09 --> 00:01:39.09

when you're doing integration tests



39

00:01:39.09 --> 00:01:42.03

of the full stack of your application



40

00:01:42.03 --> 00:01:45.08

within the confines of

a JUnit running locally.



41

00:01:45.08 --> 00:01:48.01

This is really powerful

in these integration tests



42

00:01:48.01 --> 00:01:50.07

where we don't want to reach

out to a remote server.



43

00:01:50.07 --> 00:01:52.00

We want to run it all locally



44

00:01:52.00 --> 00:01:55.00

with the proper servlet context.



45

00:01:55.00 --> 00:01:56.06

We also get the addition



46

00:01:56.06 --> 00:01:58.08

of conditional running of our tests,



47

00:01:58.08 --> 00:02:00.08

and the benefit here is that we can use



48

00:02:00.08 --> 00:02:04.09

the all-familiar Spring Expression

Language to do our work.



49

00:02:04.09 --> 00:02:06.06

So we get two annotations here,



50

00:02:06.06 --> 00:02:08.06

EnabledIf and DisabledIf,



51

00:02:08.06 --> 00:02:11.08

and you can see what those

are for just by the names.



52

00:02:11.08 --> 00:02:13.06

The conditionals there can be anything,



53

00:02:13.06 --> 00:02:16.01

including in Spring Expression Language,



54

00:02:16.01 --> 00:02:18.02

which allows us to look at properties



55

00:02:18.02 --> 00:02:20.06

and other values within the ecosystem



56

00:02:20.06 --> 00:02:23.00

and determine if we should

run the test or not.



57

00:02:23.00 --> 00:02:25.09

Things like profiles are

really powerful here.



58

00:02:25.09 --> 00:02:27.08

Now, this can be applied at a method level



59

00:02:27.08 --> 00:02:29.01

or at a class level,



60

00:02:29.01 --> 00:02:30.06

so if we have an entire class



61

00:02:30.06 --> 00:02:32.09

that we don't want to

run if we're on a Mac,



62

00:02:32.09 --> 00:02:34.09

for instance, we can do that.



63

00:02:34.09 --> 00:02:37.00

Or an entire class that we want to run



64

00:02:37.00 --> 00:02:38.01

if we're in this condition,



65

00:02:38.01 --> 00:02:40.00

or just an individual test,



66

00:02:40.00 --> 00:02:42.03

that conditional running

becomes very powerful



67

00:02:42.03 --> 00:02:44.02

in those situations.



