Introduction to JUnit

     For this course, we are expected to implement tests to a Java program. For that reason, we will be using JUnit. As Eclipse is the framework I am familiarized with, it will we be the one I’ll use during this course. Also, Eclipse comes with an extension that allows the developer to create tests. In my case, I did not need to install anything else besides the Eclipse I already had.

     First you create the Java class that you want to test. In this case, we will be using the class BoundedQueue.java that can be found in the codes of Chapter 3 from the course book.

     For creating the test class we go to File >> New >> JUnit Test Case as shown in the image below.

1

 

The following window will appear:

2

     In Source Folder,  we make sure we are on the same folder as the class we aim to test; same goes for the Package. On Name, we write the name we want for our testing class. In this case, it will be BoundedQueueTest.java. On the field Superclass, we make sure it says java.lang.Object. And in Class under test, we select the class we want to test; in this case is BoundedQueue.java.

     What I know so far, is that every method that you create is a test. The interface will only tell you if the test was passed or not. Also, every method is like a small main method in the class. For that reason, there is no communication between test methods.

      So, we create a method called SetUp() in which we will instantiate those variables that we will be using along the class. Before this method, we need to write @Before (not sure why, if you don’t it marks it as an error). Eclipse will ask you to import a class in order to use this, so just do so.

3

      Then we continue with the test methods; for which you need to write @Test before them (also not sure why). These methods can be named however you like, but I suggest to explain what you are trying to do in the name.

4

     In the previous example, we tried to create take out an element of an empty BoundedQueue. When we run this, Eclipse will tell us that the test failed and why it failed:

5

 

For the complete code go to: https://github.com/florethge/Software-Quality-and-Testing/blob/master/UnitTestChapter3/BoundedQueueTest.java

Kent Beck Audio

Kent Beck is a software engineer known for its contributions in extreme programming, test driven development, refactoring and design patterns.

During this interview, Kent Beck introduces us to Agile Development. This type of development procedure incentives the developer to create small chunks of code that can be tested easily. For doing this, we need to know which parts of the code needs to be done first, and for this, we need to know which parts depend from which so we can start by making the most reliable pieces of code.

Once you’ve done a small piece of code, test it. Once you’ve made sure that it passes all the tests, you commit it. Do not ever submit code that has not been tested or that it failed the tests. If later you find out that some part of the code done previously is causing the code to crash, you can always go back to a previous version where it worked but it didn’t have the part you are trying to delete.

Also, it encourages us TDD as a method for testing. This method consists on creating the test before creating the code. This way, we know exactly what we want the software to do before we code it. And after we create it, we can test it using the test we developed before. If it passes the test, we know that our software does exactly what it need to do and then we only need to make small changes.

If we combine the agile programming technique with the TDD method, we get a series pf sprint in which the test was created before the code, and the code does exactly what it needs to do in order to pass the test.

Week 2 delivery

On Monday, we stated that by the end of the week we would have finished the following tasks:

  • Get familiar and a brief introduction to software testing.
  • Read Chapter 1 of the Introduction to Software Testing Book.
  • Define team roles.
  • Figure out which project are we going to be working on this semester.
  • Share Github credentials (Usernames).
  • Set up Github Team Repository.
  • Brief Review on how to use Github.
  • Get to now each other, by sharing cellphone numbers and creating a WhatsApp group.

 

To this day, we have achieved most of what we were supposed to. However, we still have no idea on what project we will be working along the semester as we have some doubts we plan to ask Ken on Moday.