Java Eclipse Tutorial - Part 9: Running JUnit Tests смотреть онлайн
NEED TO LEARN JAVA - 5 FREE JAVA VIDEO COURSES - CLICK HERE - https://goo.gl/7i95F8
---
Download Source Code: http://www.luv2code.com/?p=936
Take the FULL course: http://goo.gl/042JWo
SUBSCRIBE to this channel: http://goo.gl/EV6Kwv
Website: http://www.luv2code.com
---
Website: http://www.luv2code.com
YouTube: http://goo.gl/EV6Kwv
Twitter: http://goo.gl/ALMzLG
Facebook: http://goo.gl/8pDRdA
View more videos on my “Eclipse Playlist”: http://goo.gl/R3p3m8
---
In this video tutorial, I will show you how to run JUnit tests Eclipse. I will discuss the following topics:
• Create a Unit Test
• Running the Test
---
Video Transcript
Time - 00:00
Hi, this is Chad (shod) with luv2code.com. Welcome back to another tutorial on Eclipse. In this video, you'll learn how to use JUnit in Eclipse.
Time - 00:12
I'll cover the following topics: I'll show you how to create a unit test and also how to run a unit test. Okay. Let's get started.
Time - 00:23
We need to create a method to mask a credit card number. The credit card number is a 16-digit number. We only want to show the last 4 digits, and we'll replace the other digits with an X. See the input number and the output number.
Time - 00:35
To test the code, we'll make use of a testing framework called JUnit. This is available at junit.org. Eclipse has built-in support for JUnit, so there is nothing additional we have to download. In order to use JUnit, we have to create a test case. Inside of the test case, we'll setup the input, we'll execute the method, and then compare the result against the expected output. When you run the test, it will give you a pass-fail indicator. If you pass, you'll see the green bar. If you fail, you'll see the red bar. Of course, our goal is to see the green bar.
Time - 01:09
For this tutorial, I have an empty project. What I'll do first is create a simple step for the method. The method will be called Mask and it will take a string for the credit card number. When doing unit testing, you'll provide just a simple implementation of the method. Then, you'll come back and you'll add the real functionality to the method later.
Time - 01:31
Now, let's add a new unit test for this. First, we'll add a new source folder and call it test. Then, we'll also add a new package using the same package name as our class. Then, we'll go through and add an actual JUnit test called CreditCardUtilsTest. We'll select the actual class that we're going to test against CreditCardUtils, and we'll keep all of the other defaults and then we'll simply hit Finish.
Time - 02:16
Now, let's add some code for this actual test. The first thing we'll do is we'll setup with the actual credit card number that we're going to use for testing. Stub out some coding for executing assert. Here, I'll go through and I'll execute using this credit CreditCardUtils.mask method.
Time - 02:38
I'll pass in the credit card number. Then, I'll come over here and I'll setup the expected value that should be returned, and then I'll check to see if those two values are equal, so I'll do assertEquals and give the expected value, the actual result.
Time - 02:59
Now, let's go ahead and run the test. We'll just do a right click. We'll select Run As and JUnit test. In the top left corner, you'll see the results. No, we have the red bar meaning that we failed, and we expect that because we didn't put any real implementation code in our CreditCardUtils class.
Time - 03:18
All right, so let's go ahead and add some real code. I'll move into this method. I'll remove that old piece of code and now I'll say return. I'll give the mask of the first 12 x's and then I'll do a substring, and I'll get the last 4 characters of this number.
Time - 03:43
Now, what I like to do is go ahead and run the unit test. I'll right click, say Run As, JUnit test, and then I'll just check for the results in the top left corner, and wow we have a green bar. That's great, so our unit test passed.
Time - 03:58
However, right now our unit test passed a very simple case. What happens if we give it bad data? Like we pass on the no value. What happens? I'm going to add another unit test here called test_nulls, and this will basically set the credit card number to null and it'll call the method.
Time - 04:12
Now, this should give us an IllegalArgumentException. We have that setup as expected for this test, so let' go ahead and save this and then we'll run it and we'll see what the results are. Run As, JUnit test, and now on the top left we have red, okay. One of the tests failed, so we passed in a null value and it didn't like that no value. We need to fix this, so how can we do that?
Что делает видео по-настоящему запоминающимся? Наверное, та самая атмосфера, которая заставляет забыть о времени. Когда вы заходите на RUVIDEO, чтобы посмотреть онлайн «Java Eclipse Tutorial - Part 9: Running JUnit Tests» бесплатно и без регистрации, вы рассчитываете на нечто большее, чем просто загрузку плеера. И мы это понимаем. Контент такого уровня заслуживает того, чтобы его смотрели в HD 1080, без дрожания картинки и бесконечного буферизации.
Честно говоря, Rutube сегодня — это кладезь уникальных находок, которые часто теряются в общем шуме. Мы же вытаскиваем на поверхность самое интересное. Будь то динамичный экшн, глубокий разбор темы от любимого автора или просто уютное видео для настроения — всё это доступно здесь бесплатно и без лишних формальностей. Никаких «заполните анкету, чтобы продолжить». Только вы, ваш экран и качественный поток.
Если вас зацепило это видео, не забудьте взглянуть на похожие материалы в блоке справа. Мы откалибровали наши алгоритмы так, чтобы они подбирали контент не просто «по тегам», а по настроению и смыслу. Ведь в конечном итоге, онлайн-кинотеатр — это не склад файлов, а место, где каждый вечер можно найти свою историю. Приятного вам отдыха на RUVIDEO!
Видео взято из открытых источников Rutube. Если вы правообладатель, обратитесь к первоисточнику.