Introduction to Unit Testing in Java with J-Unit 4
3.9 (16 ratings)
Instead of using a simple lifetime average, Udemy calculates a course's star rating by considering a number of different factors such as the number of ratings, the age of ratings, and the likelihood of fraudulent ratings.
246 students enrolled
Wishlisted Wishlist

Please confirm that you want to add Introduction to Unit Testing in Java with J-Unit 4 to your Wishlist.

Add to Wishlist

Introduction to Unit Testing in Java with J-Unit 4

Everything you need to learn to get up an running writing unit tests, including tools, strategies, and techniques.
3.9 (16 ratings)
Instead of using a simple lifetime average, Udemy calculates a course's star rating by considering a number of different factors such as the number of ratings, the age of ratings, and the likelihood of fraudulent ratings.
246 students enrolled
Created by Brian Gorman
Last updated 7/2017
English
Current price: $10 Original price: $20 Discount: 50% off
5 hours left at this price!
30-Day Money-Back Guarantee
Includes:
  • 1.5 hours on-demand video
  • 1 Article
  • Full lifetime access
  • Access on mobile and TV
  • Certificate of Completion
What Will I Learn?
  • Learn J-Unit Syntax
  • Understand what it means to "Assert" code is working as expected
  • Learn strategies for testing code
  • Learn techniques for testing code
  • Understand differences between J-Unit 3 and J-Unit 4
View Curriculum
Requirements
  • Java Programming basic knowledge
  • A computer
  • Ability to solve problems
Description

Unit testing is not a new idea, but it has become much more popular in the days of Agile and continuous, iterative development. Unit tests ensure that quality code is written, and gives the developer and the team the peace of mind to know that changes to the system can be made with confidence.

This short module is designed to be like a one-day training session, where the user can come in only knowing how to program in java and leave knowing how to create unit tests against their java code.

By the time you've completed this course, you'll know how to create a unit test, as well as understand the different attributes used in testing, along with the valid commands to issue to write good tests.

Additionally, this course will help you to learn how to use TDD as a driver for all of your development efforts going forward. With a "test-first" approach, we change our standard viewpoint of how we write code. Now, not only do we think about "how do I make this code work," we also think about "how do I break this code" or more often, "what happens when the user or system doesn't play nice with our code?"

This course is structured to take you anywhere from 2-8 hours to complete, depending on how much of the work you do on your own or just use from the provided samples. The lessons and knowledge build from the ground up, but the last few lessons could be done in any order, depending on your needs.

If you've ever wondered how to get started with unit testing, this is the course for you. This course would also be good for anyone looking to implement testing in future and existing development efforts.

Who is the target audience?
  • Anyone who wants to learn about unit testing
  • You should already have a basic understanding of programming languages
  • Anyone curious about what unit tests are and why would we use them
Students Who Viewed This Course Also Viewed
Curriculum For This Course
14 Lectures
01:24:45
+
Getting Started
14 Lectures 01:24:50

This video is a welcome to our course and an overview of what is to come. During this video, we discuss what you will and won't learn in this course module, as well as some expectations about the amount of time it will take to go through this course.

Preview 03:32

This video is the first part of two parts of an introduction to testing. In this part, we go over some of the major arguments against testing and talk about how testing is actually very important, even if there is a bit more work up front.

Preview 08:37

In this video, we conclude our introduction to testing by discussing some testing strategies and the unit testing methodologies. We also look at the different assertions and how we'll use assertions to pass or fail the unit tests.

Introduction to Unit Testing in Java with J-Unit 4 - Part 2
06:55

In this video, we go over creation of the unit tests in Eclipse and start our Person object and testing on the Person object, working from the ground up. After we get the test class and JUnit libraries in place, we begin our testing by testing the Person class constructors.

There are two sets of files for this video. The starter pack and the finished code. I highly recommend starting with the starter pack and working along with me. If you get stuck, there are some text files that contain finished versions of the code in both projects. If you are pressed for time and just want to review, or if you have completed the video and want to check your work, take a look at the finished version to compare results or see the end result of this part of the project.

Creating the Tests and Writing Tests for Constructors
08:40

In this video, we continue our look at testing by adding the tests and then coding the accessors (getters) and mutators (setters) for our Person class instance variables.

As before, there are two sets of files for this part of the project. I again recommend using the starter pack and working along with me. The finished version is there for your convenience as well.

Testing Mutators and Accessors, and finish Constructor Testing
11:39

In this video, we continue testing our Person object by writing the tests to verify the toString() method is working as expected.

We'll just verify toString() contains our expected property values using the contains method of the String class. If you need to do more thorough testing, like validating a specific format, you could do that here as well.

As before, there are two sets of files for this part of the project. I again recommend using the starter pack and working along with me. The finished version is there for your convenience as well.

Testing the toString() method
05:39

In this video, we start our examination of how we'll go about testing the Comparable interface, which will implement in the Person class. This method can sometimes be tricky to implement, so we'll take some time planning before we get started. Some good things to think about will be what inputs can be sent to the method, what specific values we want to return, and what the order of precedence will be for determining if one person is greater than, less than, or equal to another person.

Comparable is an important interface to implement when we are going to be ordering objects. It is very conceivable that an object like person would need to be ordered by last name, then first name, and sometimes we'll care about age as well. We take all three into account in this class.

Please find the planning spreadsheet and pdf/Word Document that I used attached to this video for your reference.

Planning Testing for implementation of the Comparable interface
07:56

In this video, we go over the implementation of the Comparable interface and take the time to work through some of the testing. The amount of testing needed would go far too long for the video, so a set of instructions exists that allows you to follow through with creating all the tests and learn more about the TDD process.

As with the other testing sessions, I recommend getting the starter pack and working through to the end. The finished code is also available for you to review.

Testing the Comparable Interface
08:05

In this video, we take the time to discuss how the equals method works, and how we can override it and test it in our Person class. Once again, we'll benefit from our grid that helps us see which cases we really need to focus on for comparing to determine if two Person objects are equal.

Planning Testing for overriding equals()
04:12

In this video, we take a look at writing the code and tests for the equals() method. Once again, we'll do part of it in the video but it's up to you to practice it.

As with other videos in this section, we have both a starter and finished version of the project. There is also a step-by-step document for adding tests and code to PersonTest and Person classes.

Testing the equals() method
06:31

In this video, we take the time to look at how we can test exceptions in J-Unit 4. With J-Unit 4 exception testing, we can use the @Test(expected=...) attribute to specifically identify the exception class that we expect should happen when our code executes. This is an extremely handy feature and makes testing for exceptions very convenient.

There are some things to remember. For example, once an exception happens, test code will immediately stop execution, so we don't want to put test code after the line in our test that we expect to trigger the exception.

Additionally, we'll need to write a specific test for each exception that we expect could happen in method. If there are multiple exceptions that could happen, make sure to write a test for each one.

Finally, we need to remember to also check to make sure valid code is not triggering the exception. A good way to begin to write the test then is to expect the exception and only have the valid code. The valid code should not trigger the exception so the test should fail (when no exception is thrown). Then add the code that should trigger the exception, and your test will now pass as expected.

Testing Exceptions
07:08

This video is a brief discussion of the major differences in syntax between J-Unit 4 and J-Unit 3. By the end of the video, you should be able to easily write tests in either version, based on what we've already learned about testing and how tests would be structured in both J-Unit 4 and J-Unit 3.

J-Unit 3 Syntax differences
03:54

This video is the conclusion for our course. I hope you enjoyed this course and would love to hear any feedback you have for me, either good or bad! Again, I wish you all the best in the future!

Course Wrap-Up
01:32

This is a bonus lecture and has nothing to do with the course.

Bonus Lecture: Links and coupons to other courses I offer
00:30
About the Instructor
Brian Gorman
4.3 Average rating
1,829 Reviews
44,554 Students
5 Courses
Software Engineer and Computer Science Instructor

I am an experienced .Net developer, previously certified as an MCSD .Net in C#.net [expired]. I have a masters of science degree in computer information systems, and a bachelor of science degree in computer science. I also have many years of experience instructing college courses online in SQL databases, C#/VB .Net programming, Java programming, and Microsoft Office. I have created many online technical training courses that can be found on various platforms like O'Reilly/InfiniteSkills, Udemy, and others. I also run MajorGuidanceSolutions, a training and consulting company ,while working fulltime as a .Net developer.