Detailed Notes
Welcome to another edition of Developreneur. Today we are going to be talking about AssertJ packages. AssertJ is a fluent assertion library in Java for unit testing. Therefore, instead of using the traditional JUnit Assert class, we will discuss this new library, AssertJ. Today we'll be looking at unit testing with Assert J. We'll briefly talk about the differences between assertions and why they're essential within unit testing. And then, we're going to go into a full HandsOn presentation using assert j methods and chaining within our unit testing.
What is Unit Testing?
Let's begin by talking about unit testing. Unit testing is software testing, where we test the individual units of our source code. Here we focus on testing particular methods or units of work, not the general application. We're not doing regression or integration testing on the different integration points or other applications. We want to focus on a specific unit of work, potentially a method in our code.
Why is unit testing necessary?
First, it helps us to identify problems early in the development cycle. Then it lets us quickly catch bugs or issues with our code changes at development time. So as we're writing the code, we can test the code and say, oops, our change broke something, or everything passed, and we can then move on. Finding and fixing bugs at this level is very cost-effective because we can fix them now. Whereas if we waited till we did regression testing or manual testing of the application once it's been packaged and shipped. It will be harder for us to identify what that bug is or where that problem came from in the code.
Finding and fixing bugs at this level is very cost-effective because we can fix them now.
The importance of Unit testing
With Unit testing, we can quickly catch most of the functionality bugs within our application during development. It also makes debugging the process easier because if we see the bug in our unit test, we know specifically in our code where it broke. We know where to fix the problem. Again, if we wait till the end when we're trying to package and ship the product, we don't necessarily know where the bug exists. So it will take more time and effort to go back in and dig into the code and find the problem. The other nice thing about unit testing is we can reuse our code to migrate our specific test from one application to another. So if we have similar code in one application, we could copy that unit test, put it into the other code base, make a couple of tweaks, and be done.
Why is unit testing so effective?
Unit testing is the first line of testing that developers can do while writing their source code. Now, this leads to assertions. So what are assertions? The Oxford Dictionary defines assertion as a confident and forceful statement of fact or belief. Which translates into what we're looking at when we talk about testing. Junit or unit testing defines an assertion as a collection of utility methods that support asserting test conditions. It is easy to take a test scenario or some test data and test something. We want to make sure that things work.
An assertion is a confident and forceful statement of fact or belief.
So what is AssertJ?
AssertJ is a library or a third-party library that you can include in your project that is rich and easy to use. It is extensible and open source so that you can extend the libraries. It is also community-driven, so there are no licenses or costs to using this library. AssertJ provides a rich set of assert classes and methods that provide excellent error messages. It improves test code readability and is easy to use within your favorite IDE.
Why should I use AssertJ instead of plain Assert classes?
The whole reason I'm even talking about AssertJ today is that once I found and started using this, it made writing those unit tests, asserts, and use cases easier to read and follow. Instead of having to create a whole bunch of independent asserts with the traditional assert libraries that come with Junit or some of the other unit libraries. It made a difference in the way I write Unit tests.
Hands on with AssertJ
In the video, we also provide a hands-on demo of the different APIs between JUnit and AssertJ. Including a sample unit test highlighting some of the functionalities that come with AssertJ.
Finally, this series comes from our mentoring/mastermind classes. These classes are virtual meetings that focus on how to improve our technical skills and build our businesses.  After all, the goals of each member vary.  However, this diversity makes for great discussions and a ton of educational value every time we meet.  We hope you enjoy viewing this series as much as we enjoy creating it. As always, this may not be all new to you, but we hope it helps you be a better developer.
Transcript Text
foreign [Music] [Music] so welcome to another edition of developer today we are going to be talking about a certain J packages and it is a fluent assertions in Java so instead of us using the traditional junit assert class we're going to be talking about this new library assert J So today we're going to be looking at unit testing with the cert J we're going to kind of briefly talk about the differences between or what assertions are and why they're important within unit testing and then we're going to go into a full Hands-On presentation using assert J methods and chaining within our unit testing so first let's talk about unit testing so unit testing is software testing where we're testing the individual units of our source code so we're testing individual methods we're testing units of work we're not testing the overall application we're not testing we're not doing regression testing we're not doing integration testing within our application and other applications this is solely focused on a specific unit a potentially a method in our code why is unit testing important well it helps us to identify problems early in the development cycle this lets US Weekly catch bugs or issues with our code changes at development time so as we're writing the code we can test the code and say oops our change broke something lower everything passed and we can then move on finding bugs and fixing bugs at this level is very cost effective because we're able to fix it now whereas if we waited till we did regression testing or manual testing of the application once it's been packaged and shipped it's going to be harder for us to identify what that bug is or where that problem came from so if we do unit testing right we should be able to catch most of the functionality bugs within our application quickly during development it also makes debugging the process easier because if we catch the bug in our unit test we know specifically in our code where it broke we know where to go fix the problem again if we wait till the end when we're trying to package and Chip the product we don't necessarily know where the bug exists so it's going to take more time and effort to go back in and dig into the code and find the problem the other nice thing about unit testing is we can also reuse our code to migrate our specific test from say one application to another so if we have similar code in one application we could potentially copy that unit test put it into the other code base make a couple of tweaks and boom we're done so unit testing very effective this is the first line of testing that developers can do while they're writing their source code now this leads into assertions what are assertions well the Oxford dictionary defines assertions is a confident and forceful statement of fact or belief which really translates into what we're looking at when we talk about testing so from the junit or unit testing perspective and assertion is essentially a collection of utility methods that support asserting conditions in tests so it's like given some test scenario when we give it some data then we want to test something we want to make sure that things work again assertions is a competent and forceful statement of fact or belief assert J is a third party library that you can include in your project that is Rich and easy to use it is extensible it's open source so you can go extend the libraries it is also Community Driven so there are no licenses or costs to using this Library assert J provides a rich set of assertions truly helpful error messaging improves test code readability and is designed to be super easy to use within your favorite IDE and the whole reason I'm even talking about the search J today is because once I found this and I started using this this really makes writing those unit testings and writing those a search writing those use cases it makes it so much more readable and easy to follow in your use cases than trying to create a whole bunch of independent asserts with the traditional assert libraries that come with junit or some of the other unit libraries so that's pretty much it for the slides so we're going to jump out we're going to look at the different apis between junit is searching and assert J and then we're going to walk through a simple use test on how to use some of the functionalities that come with the search J all right so let's first start with assertions in junit the assertion Library contains a whole bunch of helper methods that we can use to define assertions within our use cases we can do things like assert all we can assert arrays are equal to things but basically there is an assert method for every type of test that you want to do but you have to essentially assert for everything you want to do so either you create if statements around conditions or you have to basically Define multiple assertion statements in order for you to test your library so you have like a search equals a certain not equals a certain null which is really useful in and of itself like this are true fail uh but we don't necessarily want to have to have 5 10 15 asserts to essentially test a use case it gets to be unreadable unmanageable however with assert J assert J uses fluence so you can use method chaining starting with and assert that instead of assert equals so you basically start with the Declaration assert that and then you can use fluent and basically chain any of the methods within the assert J which is very useful so the two locations to look at if you want to compare these if if you go to junit.org junit Five docs and the version you want then API index.html will bring up the junit API of your choice assert J you can get to by just Googling assert J and pick whichever index you want but they are on GitHub it is a weird URL it is Joel Dash castigila Lego uh steliago anyway it's easier if you just Googled assert day go to their GitHub and then you can find the apis there go back to our code so we're going to start with a simple test here so let's look at our project here so our project is a basic Maven project I just named it a search examples for clarity for this class and I added two classes to my Java main packet so I have a calculator class from last time which has all of our methods for adding subtracting dividing multiplying basically the basic arithmetic functionalities for a calculator we have factorial and then we had our main class where we actually did the operations where we took command line arguments and actually added up or tested our methods so to start with I want to introduce instead of just jumping right into search a I want to show you how to write a unit test to test protected private methods within a class so we'll start with this one and then we'll move into testing our second class here which is a basic pojo a person with a name address city state ZIP so down in Source test Java I've created a calculator test class and we will ignore this for right now so in our calculator test it is a junit 5 test so I'm using junit Jupiter API test which allows me to use the test annotations and then I create a method to test the add to numbers method from my calculator so we want to test this right here we want to test this method but this method is protected we it's not public so I can't just say calculator add two numbers and go on so to access a method inside of a class that is protected or private you can use the method reflection class here Java link reflect method and then we can go in and we can take the class name we want dot class we can use the get declared method for the method reflection we then can specify the method that we want so essentially we're defining the method within our test so we're going to say okay get declared method we want to get the method name add so basically you kind of copy this here so you get the method name add two numbers and then you also want to set the parameter types that you're going to have to pass in so we give it the method name and then we give it the two parameter types that we want to pass in which our flow the next thing we want to do is we want to take our method reflection and we want to set it accessible so we want to set it true that way we can access that private protected method and then you can just simply use a standard assert this is not a search eight this is just a standard assert method where we can assert equals that the result of adding two numbers one and one is going to be 2 we have to add the F postfix so that we can Define this decimal as a float we call our method add two numbers returns result method invoke so we're going to invoke it we're just going to say a okay call it we Define our new calculator so we instantiate our calculator class and then we pass in two parameter values of one and one which should equal two so if we run this we should pass now if this failed it would throw the message the sum should be 2. all right so let's run this and over here if I extend this we pass but if I change this to 2 and rerun this we fail and if we expand this you'll see that the message here that we added was written out the sum should be 2 expected to but we received 3. so this is an example of using a standard assert method within our test case now if we want to use assert J we need to import some assert J classes here so we need to include org dot assert J dot core dot API Dot assertions now you could do dot star but you know in the standard world today we only want to include the classes that we want so for today's example we're going to be looking at the assert that method which is what we're going to start all of our assertions with we're going to look at a cert that throws by to actually test exceptions so we can actually kind of force an exception or a method that may throw an exception catch throwable and Tuple which will allow us to go in and actually check different values within a object which is very useful all right so let me go down here add my test data back in so for our uh sir J Test we are going to use our person class so we're going to use our person pojo to test some data that is being passed around I kind of followed the example that they used on their website I just kind of simplified it a little bit further without having to include all the additional classes they used for testing before we get to that point though you will need to also include the dependency assert J so your Maven dependency will be group ID or assert J the artifact you need is the search J dash core and currently the version uh that's out there right now is 3.4.1 and I want to set the scope to test so that when I build the project it will not include the test packages within my compiler so test one let's look at a basic assertion test so this is going to kind of be a very simple test kind of like what we did here with the assert equals so here I've created three persons or I could find three persons for testing I've created a random person John Smith and Jane Doe all with some uh different person data that we're going to test so for our first test method our basic assertions we're going to follow the chaining method the fluent method of a search a so we begin our test with assert that and then we give it our uh what we're going to test so assert that here random person dot get name so assert what it is we're checking then what do we want to test so we have assert that so let's look at this so assert that can receive a string but if we go look over here so if we look at assert that you see the assert that takes it's been overloaded to handle multiple different types so we can take files floats just about everything possible within the Java language we can take almost any type of class so we can uh pass in anything so say we want to insert a string is equal to another string so we start with the string then you can do Dot and now you have all your assertion or certain J methods that you can use so you can check for um we'll talk about as in a second but we'll stick to Strings so as string contains contains only contains all patterns so you have a whole slew of methods now that you can test uh within this assert that method whereas if we just did the straight up assert equals or assert true this is a one and done you you make this method call and that's it so if you want to do another test or chain off of this test you have to create multiple assertions however here with the assert that it allows you to chain this test so not only can I assert that random person.getname is equal to random person I can also continue chaining off of the last method so I can say okay is this equal to random person okay cool is it also um equal to ignored case uh so you could actually essentially create your one test or combine all the things you're testing into one statement whereas again with the assert you would have to create multiple asserts uh that you would have to test so if one failed you would have to then have to go up okay this and figure out what failed whereas here if you change it all into one command if this guy fails you know that this is the line you need to go look at all right so let's start with the first part here so how we read this assert debt random person.getname is equal to random person very readable now if we wanted to do this up here it would be something like this so uh straight up assertion would be assert equals random person get name random person so assert equals random person get name random person still fairly readable but this reads better assert that random person get named is equal to random person a certain equals random person name random person doesn't quite roll off the tongue as easily the other thing is okay so if I did this but then I wanted to do some additional things off of this I would have to do another assert and continue whereas here if I want to do another dot is equal uh ignore case I could actually add some other chaining here if I wanted to where here I would have to do yet another assert all right so there's the first two or sorry first one and then the second one not only can we check by string but we can actually actually check by object type so I can say assert that random person is not equal to John Smith if we go up here so random person should be this person object and John Smith will be this object so it actually allows you to compare objects as well so if I save this and run our test pass now if I actually put in random person this should fail because random person is equal to random person and sure enough it failed so let's look at this so our assert error it's expecting a person name random person address one two three is not uh to be equal to random person so we fail another thing I like about assert J is the failure messages you get at runtime are so much easier to understand and they're clean they're easy to read uh unlike a certain methods you would have to kind of expand upon the assert methods like so okay so now we have this one put it back so it passes so that's just basic assertion so that's very simple comparison between the two so now let's look at this chaining method so the second one here is chaining so chaining allows us to chain different things we can change strings specifically we contain collections but for this one let's just start with string so here we're going to assert that [Music] johnsmith.getname dot starts with John we can also check that it ends with th and we can see if it is equal to ignored case John Smith again if we wanted to do this as assert you would have to do something like this so here we have to essentially write three assert methods to do the same thing that we can do in a search J in one line so here we can assert that John Smith dot get name starts with joh DOT ends with th dot equals ignored case John Smith a lot easier to read and very easy to understand where this gets convoluted or if you have a lot of these it's going to be hard to tell what exactly the test is doing okay put those go back to clean run this again so if we look at our chaining it passed now let's make it fail so let's say we did John by mistake the first part should fail that's passed that should still pass but the first part failed foreign and if we look we were expecting John Smith to start with John and it failed because um our name was actually j-o-h-n so it did not start with John so it failed very clean very easy to read okay put that back together H so this passes all right so that's chaining hello this is Rob with developmentor also known as building better developers wanted to announce that we have school.developmentor.com feel free to check it out if you like any of this information any of the content that we've sent and you would like to see more you can come out you can enroll for free we have free courses we've got places for you to get better at just learning a technology our how to's you can work on your business skills we can help you with becoming a better developer as encoding and things like that a lot of the stuff you've seen on YouTube we also have out at school.develop anymore we just have it a little more of a educational format and a way for you to track your progress as you move forward becoming a better developer foreign [Music]
Transcript Segments
foreign
[Music]
[Music]
so welcome to another edition of
developer today we are going to be
talking about a certain J packages and
it is a fluent assertions in Java so
instead of us using the traditional
junit assert class we're going to be
talking about this new library assert J
So today we're going to be looking at
unit testing with the cert J we're going
to kind of briefly talk about the
differences between or what assertions
are and why they're important within
unit testing and then we're going to go
into a full Hands-On presentation using
assert J methods and chaining within our
unit testing
so first let's talk about unit testing
so unit testing is software testing
where we're testing the individual units
of our source code so we're testing
individual methods we're testing units
of work we're not testing the overall
application we're not testing we're not
doing regression testing we're not doing
integration testing within our
application and other applications this
is solely focused on a specific unit a
potentially a method in our code
why is unit testing important well it
helps us to identify problems early in
the development cycle this lets US
Weekly catch bugs or issues with our
code changes at development time so as
we're writing the code we can test the
code and say oops our change broke
something lower everything passed and we
can then move on
finding bugs and fixing bugs at this
level is very cost effective because
we're able to fix it now whereas if we
waited till we did regression testing or
manual testing of the application once
it's been packaged and shipped it's
going to be harder for us to identify
what that bug is or where that problem
came from so if we do unit testing right
we should be able to catch most of the
functionality bugs within our
application quickly during development
it also makes debugging the process
easier because if we catch the bug in
our unit test we know specifically in
our code where it broke we know where to
go fix the problem again if we wait till
the end when we're trying to package and
Chip the product we don't necessarily
know where the bug exists so it's going
to take more time and effort to go back
in and dig into the code and find the
problem
the other nice thing about unit testing
is we can also reuse our code to migrate
our specific test from say one
application to another so if we have
similar code in one application we could
potentially copy that unit test put it
into the other code base make a couple
of tweaks and boom we're done
so unit testing very effective this is
the first line of testing that
developers can do while they're writing
their source code
now this leads into assertions
what are assertions well the Oxford
dictionary defines assertions is a
confident and forceful statement of fact
or belief
which really translates into what we're
looking at when we talk about testing
so from the junit or unit testing
perspective and assertion is essentially
a collection of utility methods that
support asserting conditions in tests so
it's like given some test scenario when
we give it some data then we want to
test something we want to make sure that
things work again assertions is a
competent and forceful statement of fact
or belief
assert J is a third party library that
you can include in your project that is
Rich and easy to use it is extensible
it's open source so you can go extend
the libraries it is also Community
Driven so there are no licenses or costs
to using this Library
assert J provides a rich set of
assertions
truly helpful error messaging improves
test code readability and is designed to
be super easy to use within your
favorite IDE
and the whole reason I'm even talking
about the search J today is because once
I found this and I started using this
this really makes writing those unit
testings and writing those a search
writing those use cases it makes it so
much more readable and easy to follow in
your use cases than trying to create a
whole bunch of independent asserts
with the traditional assert libraries
that come with junit or some of the
other unit libraries
so that's pretty much it for the slides
so we're going to jump out we're going
to look at the different apis between
junit is searching and assert J and then
we're going to walk through a simple use
test on how to use some of the
functionalities that come with the
search J
all right so let's first start with
assertions
in junit the assertion Library contains
a whole bunch of helper methods that we
can use to define assertions within our
use cases we can do things like assert
all we can assert arrays are equal to
things
but basically there is an assert method
for every type of test that you want to
do but you have to essentially assert
for everything you want to do so either
you create if statements around
conditions or you have to basically
Define multiple assertion statements in
order for you to test your library so
you have like a search equals
a certain not equals a certain null
which is really useful in and of itself
like this are true fail uh but we don't
necessarily want to have to have 5 10 15
asserts to essentially test a use case
it gets to be unreadable unmanageable
however with assert J assert J uses
fluence so you can use method chaining
starting with and assert that
instead of assert equals so you
basically start with the Declaration
assert that and then you can use fluent
and basically chain any of the methods
within the assert J which is very useful
so the two locations to look at if you
want to compare these if if you go to
junit.org junit Five docs and the
version you want then API
index.html will bring up the junit API
of your choice assert J you can get to
by just Googling assert J and pick
whichever index you want but they are on
GitHub it is a weird URL it is Joel Dash
castigila Lego uh steliago anyway it's
easier if you just Googled assert day go
to their GitHub and then you can find
the apis there
go back to our code
so we're going to start with a simple
test here
so let's look at our project here so our
project is a basic Maven project I just
named it a search examples for clarity
for this class
and I added two classes to my Java main
packet so I have a calculator class from
last time which has all of our methods
for adding subtracting dividing
multiplying basically the basic
arithmetic functionalities for a
calculator
we have factorial and then we had our
main class where we actually did the
operations where we took command line
arguments and actually added up or
tested our methods so to start with I
want to introduce instead of just
jumping right into search a I want to
show you how to write a unit test to
test
protected private methods within a class
so we'll start with this one and then
we'll move into testing our second class
here which is a basic pojo a person with
a name address city state ZIP so down in
Source test Java I've created a
calculator test class
and we will ignore this for right now
so in our calculator test it is a junit
5 test so I'm using junit Jupiter API
test
which allows me to use the test
annotations
and then I create a method to test the
add to numbers method from my calculator
so we want to test this right here we
want to test this method
but this method is protected we it's not
public so I can't just say calculator
add two numbers and go on
so to access a method inside of a class
that is protected or private you can use
the method reflection class here Java
link reflect method
and then we can go in and we can take
the class name we want dot class we can
use the get declared method for the
method reflection we then can specify
the method that we want
so essentially we're defining the method
within our test so we're going to say
okay get declared method we want to get
the method name add so basically you
kind of copy this here so you get the
method name add two numbers and then you
also want to set the parameter types
that you're going to have to pass in
so we give it the method name and then
we give it the two parameter types that
we want to pass in which our flow
the next thing we want to do is we want
to take our method reflection and we
want to set it accessible so we want to
set it true that way we can access that
private protected method
and then you can just simply use a
standard assert this is not a search
eight this is just a standard assert
method where we can assert equals that
the result of adding two numbers one and
one is going to be 2 we have to add the
F postfix so that we can Define this
decimal as a float we call our method
add two numbers returns result method
invoke so we're going to invoke it we're
just going to say a okay call it
we Define our new calculator so we
instantiate our calculator class and
then we pass in two parameter values of
one and one which should equal two so if
we run this we should pass now if this
failed it would throw the message the
sum should be 2. all right so let's run
this
and over here if I extend this we pass
but if I change this to 2 and rerun this
we fail and if we expand this
you'll see that the message here that we
added was written out the sum should be
2 expected to but we received 3.
so this is an example of using a
standard assert method within our test
case
now if we want to use assert J we need
to import some assert J classes here so
we need to include org dot assert J dot
core dot API Dot assertions
now you could do dot star but you know
in the standard world today we only want
to include the classes that we want so
for today's example we're going to be
looking at the assert that method which
is what we're going to start all of our
assertions with we're going to look at a
cert that throws by to actually test
exceptions so we can actually kind of
force an exception or a method that may
throw an exception
catch throwable and Tuple which will
allow us to go in and actually check
different values within a object which
is very useful
all right so let me go down here
add my test data back in
so for our
uh sir J Test we are going to use our
person class so we're going to use our
person pojo to test some data that is
being passed around
I kind of followed the example that they
used on their website I just kind of
simplified it a little bit further
without having to include all the
additional classes they used for testing
before we get to that point though you
will need to also include the dependency
assert J so your Maven dependency will
be group ID or assert J
the artifact you need is the search J
dash core
and currently the version uh that's out
there right now is 3.4.1 and I want to
set the scope to test so that when I
build the project it will not include
the test packages within my compiler
so test one let's look at a basic
assertion test so this is going to kind
of be a very simple test kind of like
what we did here with the assert equals
so here I've created three persons or I
could find three persons for testing
I've created a random person John Smith
and Jane Doe all with some uh different
person
data that we're going to test
so for our first test method our basic
assertions we're going to follow the
chaining method the fluent method of a
search a so we begin our test with
assert that
and then we give it
our uh what we're going to test so
assert that here random person dot get
name
so assert
what it is we're checking
then
what do we want to test so we have
assert that so let's look at this so
assert
that
can receive a string
but if we go look over here
so if we look at assert that
you see the assert that takes it's been
overloaded to handle multiple
different types so we can take files
floats just about everything possible
within the Java language we can take
almost any type of class
so we can uh pass in anything so say we
want to insert a string
is equal to another string
so we start with the string
then you can do Dot and now you have all
your
assertion or certain J methods that you
can use so you can check for
um we'll talk about as in a second but
we'll stick to Strings so as string
contains contains only contains all
patterns so you have a whole slew of
methods now that you can test
uh within this assert that
method
whereas if we just did the straight up
assert equals or assert true this is a
one and done you you make this method
call and that's it
so if you want to do another test or
chain off of this test you have to
create multiple assertions
however here with the assert that it
allows you to chain this test so not
only can I assert that random
person.getname is equal to random person
I can also continue chaining off of the
last method so I can say okay is this
equal to random person okay cool is it
also
um equal to ignored case uh so you could
actually essentially create your one
test or combine all the things you're
testing into one statement whereas again
with the assert you would have to create
multiple asserts uh that you would have
to test so if one failed you would have
to then have to go up okay this and
figure out what failed whereas here if
you change it all into one command if
this guy fails you know that this is the
line you need to go look at
all right so let's start with the first
part here so how we read this assert
debt random person.getname is equal to
random person
very readable now if we wanted to do
this up here it would be something like
this so uh straight up assertion would
be assert equals
random person get name
random person
so assert equals random person get name
random person
still fairly readable but this reads
better assert that random person get
named is equal to random person
a certain equals random person name
random person doesn't quite roll off the
tongue as easily the other thing is okay
so if I did this but then I wanted to do
some additional things off of this I
would have to do another assert and
continue whereas here if I want to do
another dot is
equal
uh ignore case I could actually add some
other chaining here if I wanted to
where here I would have to do yet
another assert
all right so there's the first two
or sorry first one and then the second
one
not only can we check by string but we
can actually actually check by object
type so I can say assert that random
person
is not equal to John Smith
if we go up here so random person should
be this person object and John Smith
will be this object so it actually
allows you to compare objects as well
so if I save this and run
our test pass
now if I actually put in random person
this should fail because random person
is equal to random person
and sure enough it failed
so let's look at this so our assert
error it's expecting a person name
random person address one two three
is not uh to be equal to random person
so
we fail
another thing I like about assert J is
the failure messages you get at runtime
are so much easier to understand and
they're clean they're easy to read uh
unlike a certain methods you would have
to kind of expand upon the assert
methods like so
okay so now we have this one put it back
so it passes
so that's just basic assertion so that's
very simple comparison between the two
so now let's look at this chaining
method so the second one here is
chaining
so
chaining allows us to chain different
things we can change strings
specifically we contain collections but
for this one let's just start with
string
so here we're going to assert that
[Music]
johnsmith.getname dot starts with John
we can also check that it ends with th
and we can see if it is equal to ignored
case
John Smith
again if we wanted to do this as assert
you would have to do something like this
so here we have to essentially write
three assert methods to do the same
thing that we can do in a search J in
one line
so here we can assert that John Smith
dot get name starts with joh DOT ends
with th dot equals ignored case John
Smith
a lot easier to read and very easy to
understand where this gets convoluted or
if you have a lot of these it's going to
be hard to tell what exactly the test is
doing
okay
put those go back to clean
run this again
so if we look at our chaining it passed
now let's make it fail
so let's say we did John by mistake
the first part should fail that's passed
that should still pass but the first
part failed
foreign
and if we look we were expecting John
Smith to start with John and it failed
because
um our name was actually j-o-h-n
so it did not start with John so it
failed
very clean very easy to read
okay put that back together H so this
passes
all right so that's chaining
hello this is Rob with developmentor
also known as building better developers
wanted to announce that we have
school.developmentor.com feel free to
check it out if you like any of this
information any of the content that
we've sent and you would like to see
more you can come out you can enroll for
free we have free courses we've got
places for you to get better at just
learning a technology our how to's you
can work on your business skills we can
help you with becoming a better
developer as encoding and things like
that a lot of the stuff you've seen on
YouTube we also have out at
school.develop anymore we just have it a
little more of a educational format and
a way for you to track your progress as
you move forward becoming a better
developer
foreign
[Music]