DevOps and Linux practice pt. 2

After setting up our development environment and practicing a little bit with cron in part 1, it’s time to do something useful with it. But first, lets make sure that my repository and account are safe.

1.- Setting up 2FA

GitHub has the option to connect with 2 factor authentication to your account, I have activated this option and now after signing up in an unknown device they ask for a number that they send to my phone via SMS. Now, whenever I try to push from the terminal when I’m not logged in it won’t accept my password account, this happens because with 2FA I have to generate a token and use that token as my password. I use two tokens, one for Linux and the other for Windows, they both have the minimal permissions to let me push into the repository but not delete or modify anything important from that repository or others as well.

2.- Setting up SHH keys

To avoid copying and pasting that token each time I want to use my account in the terminal there is a alternative, the SSH keys. To generate one I followed this complete tutorial, now I can connect with the key from any place I want.

3.- Cron server update automation

Now for the cron practice, I already changed the bash script to do a pull instead of just printing hello world. Also, I considered to change the cron file to run the script every 12 hours. I’m still not sure how often I should update, or how often companies do it in a real life development environment, but 12 hours seemed reasonable for me because it updates the server when people(me) are supposedly not updating the repository. However, the problem with this is that if someone pushes a broken piece of code, it will not be fixed until the next 12 hours or that someone corrects the bug and pulls manually from the server. For this practice I need to watch consistent changes, so I’m going to change the script to do a pull each minute. Whenever the server pulls any change, the website updates with a refresh if it is a simple change like a text line in the html, but I need to run it again if something like new dependencies and a JS script were added. I’m not sure if this happens because I’m using NodeJS to run the server or if this is a normal behavior, but Node already has some solutions related to this, check this site if you want to see how to use the node demon or you want to avoid refreshing the web page each time the server updates. I’m not implementing any of this for now, but I will consider it for the next practices. To ensure that the server is not running two copies of the same script there are several techniques, a simple solution is to create a file and after making the pull deleting the file. Before creating the file we should check if it already exists, if it does, then wait until the script that created it deletes it; if it doesn’t exists; then there is no concurrency and everything should execute normally.  I added this solution in the bash script, to do that I had to learn first how to do it. This bash cheat sheet helped me a lot, I think is a very useful resource when you are coding scripts.

Python unit tests

Today’s activity is really interesting, we have to do some practice with python unit testing. According to the official unittest documentation, it’s very similar to JUnit, so we should have no problem understanding it.

Now, here is a picture of me using hypothesis to do annotations on an old web page that we are able to see thanks to Wayback Machine.


While playing a little bit with Wayback Machine I found an old version of Steam’s page, the popular PC gaming platform, back in 2002. Its interesting to see that web pages were not that colorful or filled with images, this design was simple but worked really well.


For the next part, we have to see this Unit Testing and Test Driven Development in Python course where we will learn to set up virtual environments and unit tests using Pytest. For the exercises we are going to use PyCharm, a Python IDE that will make easier for us to run tests.


The tutorial was fun and explained very well the basic functionalities that Pytest has. The activities were helpful summarize all the material and I felt that they were easy to do and understand.  Overall, Pytest is a very simple but powerful testing framework for Python, it’s really easy to use and has a lot of functionalities that solve testing problems like mocking objects and exceptions catch. It’s easy to setup as well, thanks to PyCharm I had no trouble at all when I was implementing my first tests. All the time I felt like I was using JUnit but with different syntax. At the end, Richard Wells also explained some TDD good practices, and one that called my attention was to run tests in random order, I hadn’t thought that it’s important to make sure that tests should run in any order which means that they don’t have any dependencies between each other. For other specific testing processes like coverage tools, advanced mocking or linting there are other libraries or modules that work very well with Pytest.

Chapter 6 activity

What two properties must be satisfied for an input domain to be properly partitioned? 

– The partition must cover the entire domain (completeness)
– The blocks must not overlap (disjoint)

What is an Input Domain Model (IDM)? 

An input domain model (IDM) represents the input space of the system under the test in an abstract way. It helps the test engineer to define and create better tests by establishing the structure of the input domain and partitions of this domain.

What gives more tests, each choice coverage or pair-wise coverage?

Pair wise, as it does a permutation for a value from each block with one of each block of the other characteristics.

DevOps and Linux practice

This week we are going to learn about Development Operations. Its a topic that I hear very often in the industry and I didn’t know really well what this was about. If you want to learn more about what DevOps is, I made a blog post summarizing a reading about that here.

For this blog I’m going to be completing some task that show the job of a Dev Ops engineer in a simple way. For each achievement I’m going to talk about my experience:

1.- Install a Linux distribution

I already have a partition of Ubuntu Desktop 16 in my laptop, I use it for some classes or when I need to go full developer mode(no video games). I installed it a while ago, I chose Ubuntu because it is a popular choice for newcomers and students. It’s easy to customize and looks pretty, there might be better choices but at the moment I don’t have the necessity to change my Linux distribution.

2.- Install support for your development environment.

This task is really important, here is where we chose our tools, programming languages, text editors, libraries and everything else we need to have our development environment ready to go. Most of the choices I made here were just determined by preference. It’s important too that you customize your environment as you want, choose the text editor you are most used to, the tools you prefer and the themes you like; remember that you are most likely be working here a lot of time, so it does not hurt to make it easier for you.

Languages: I already have Python 2 and 3, Java, C and C++. That includes any compiler or installation needed.

Code editor: For big projects I installed Visual Studio Code, it’s a really robust editor with a lot of functionalities and a lot of extensions created by the community. For quick edits I like to use Sublime, it may have less functionalities than VSCode but is faster and also looks pretty.

Tools: I installed Git for version control, Conda to handle several environments and NodeJS to make Web Applications easily.

3.- Setup your first test use of Cron on your server.

Crontab is a very useful tool to run scripts at specific times. It’s really simple, this tutorial is enough to understand how to create a crontab file. For this practice I made a bash script that prints “Hello world” and runs every 5 minutes.

Chapter 4 and 5 activity

After reading chapter 4 and 5 from Introduction to Software Testing, we were asked to answer these questions about TDD and test coverage criteria:

  1. What is “correctness” in agile processes?
    Correctness for testing and software engineers has to do with the quantity of green tests, this means that our code is correct if it passes all the tests.
  2. Do TDD tests do a good job testing the software?
    No, TDD tests are mainly to define the requirements and specifications of our code, but not really to evaluate the right behavior or to cover edge cases.
  3. Can we automate our tests without TDD?
    Yes, automation can be done in test without following the TDD principles. Imagine writing first the code, then just executing the tests to validate it.
  4. Can we use TDD without automating our tests?
    Yes, TDD consists on putting the tests first as a guide for the code to be written, automation can help to write tests and validate faster, but is not mandatory.
  5. What four structures do we use for test criteria?
    1.- Test Requirement: A test requirement is a specific element of a software artifact that a test case must satisfy or cover.
    2.- Coverage Criterion: A coverage criterion is a rule or a collection of rules that impose test requirements on a test set.
    3.- Minimal Test Set: Test set T such that if a test was removed from T, it no longer satisfies all test requirements.
    4.- Minimum Test Set: Smallest possible test set T that satisfies all test requirements.
  6. What usually prevents our tests from achieving 100% coverage?
    What usually prevents our tests from achieving 100% coverage?
    Test requirements that cannot be satisfied are called infeasible. Formally, no test case values exist that meet the test requirements. The detection of infeasible test requirements is formally undecidable for most coverage criteria, and even though researchers try to find partial solutions, they have had only limited success. Thus, 100% coverage is impossible in practice.

  7. Some organizations in industry who adopt TDD report that it succeeds very well, and others report that it fails. Based on your knowledge of TDD and any experience you have, why do you think it succeeds sometimes but not all?
    Companies does not use TDD well, that’s why they don’t succeed using it. It is hard for some engineers to follow TDD principles, some of us are not used to write the tests first before the code.
  8. A few software organizations use test criteria and report great success. However, most organizations do not currently use test criteria. Based on your knowledge and experience, why do you think test criteria are not used more?
    We think that test criteria is very ambiguous, as we don’t have an exact default way of measuring test criteria, everyone does it differently. Maybe having a high test coverage is expensive and most of the times is not worth it, that’s why most companies decide to not focus on having  heavy testing development.

Chapter 4 activity

For this post we are going to show how we solved the exercises for chapter 4 using TDD. We need to add new operations like multiplying and division for the file. The test file only has a test for the add operation as it is the only function we have in the class.


First of all, we need to write simple tests that describe what our new operations do. Of course, these tests should fail as we haven’t coded the functions yet.


Now we can start writing the functionality now, we are going to start with the subtraction as it is the first test we should pass to move to the next one. On this exercise the order we decide to write the new functions does not matter, but in more complex projects we should have a specific order to write the new functions because some tests might have multiple dependencies.


The next step is to write the test for the divide function. Here we have a problem, we don’t know how to implement this function because it can return a double or an integer. To follow the TDD correctly first we have to make the test pass, right now the test only ask for an integer so we will write just the code to make that correct.


At last, the multiply function. Here again we ask ourselves if this function should be capable of accepting float values, but it is not specified on our tests so by now we will handle only integers for the input and output.



Now lets imagine some guys from testing added new tests, now with more specific cases trying to find faults in our code. They included a test that divides two integers but the result is non integer, a test for a division by zero,  and a test with negative integers. After running the tests this happens:


As we can notice, only the division function is not passing the new tests. On one test it is expecting float numbers, on the other test, it is expecting us to catch an error when the divisor is zero. This means that we need a refactor to return doubles and to detect divisions by zero. This will change some of our previous tests, the first division test is working but it is expecting integers, the new test is expecting  doubles, there is an inconsistency in the tests and we should define this with the team first. The final decision is that a division should return doubles because it gives a more exact result. With that information we can go back to the tests, modify them accordingly and now start working on the refactor.


With this exercise we practiced TDD and refactoring. We learned how important it is to have good tests that defines the requirements for each function and that show how specific behavior should be handled. Also, it showed us how in TDD the tests are the guideline of our code and that it can show design errors or inconsistencies before we start writing the code, a huge advantage over other methodologies.

The code of the exercise is available here:

Chapter 3 exersises

1.- Why do testers automate tests? What are the limitation of automation?
Developers automate testing to reduce costs and reduce human error, as well as making regression testing easier by allowing a test to be run repeatedly with the press of a button.
2.- Give a one-to-two paragraph explanation for how the inheritance hierarchy can affect controllability and observability:
Inheritance can make following input and output hard, since you have to keep track of multiple class definitions to be able to get an holistic view of what is going on when the tests are running. Sometimes there will be inheritance graphs so long that it feels like going up and down like a yo-yo, this yo-yo problem term was defined in “Problems in Object-Oriented Software Reuse” by Taenzer, Ganti and Poedar.
3.-Develop JUnit tests for the BoundedQueue.class.
public class BoundedQueueTest {
     * Test of enQueue method, of class BoundedQueue.
    public void testEnQueue() {
        Object o = 1;
        BoundedQueue instance = new BoundedQueue(5);
        assertEquals(instance.toString(), "[1]");

     * Test of deQueue method, of class BoundedQueue.
    public void testDeQueue() {
        Object o = 1;
        Object a = 2;
        BoundedQueue instance = new BoundedQueue(5);
        assertEquals(instance.toString(), "[2]");

     * Test of isEmpty method, of class BoundedQueue.
    public void testIsEmpty() {

        BoundedQueue instance = new BoundedQueue(5);

        assertEquals(instance.isEmpty(), true);

     * Test of isFull method, of class BoundedQueue.
    public void testIsFull() {
        Object a = 1;
        BoundedQueue instance = new BoundedQueue(5);

        assertEquals(instance.isFull(), true);

     * Test of toString method, of class BoundedQueue.
    public void testToString() {
        Object o = 1;
        Object a = 2;
        Object b = 4;
        BoundedQueue instance = new BoundedQueue(5);
        assertEquals(instance.toString(), "[2, 4, 1]");
4.-Delete the explicit throw of NullPointerException in the Min program. Verify that the JUnit test for a list with a single null element now fails.
public class MinTest {
* Test of min method, of class Min.
    @Test(expected = NullPointerException.class)
    public void testMin() {
        List list = new ArrayList();
        Object result = Min.min(list);
6.- Using the class PrimeNumbers describe 5 tests using the methods of the class to show the next points:
a) A test that does not reach the fault
b) A test that reaches the fault but does not infect
c) A test that infects the state but does not propagate
d) A test that propagates but does not reveal
c) A test that reveals a fault
For a test where we dont reach the fault we can call the method computePrime with a parameter less or equal to 0, being “computePrime(0).

This will never allow us to enter the while where we do the current operations and where the current fault is located.
For our second test, if we call the method with a parameter for example 3, being “computePrime(3)”, the program will run the part of the code where our fault is at, but since the number doesn’t end with a 9, it doesn’t infects.
For our thrid test, if we call the method with a parameter that 19, it wont add the 19 as a primer number cause of the fault in the program. But since we are not executing the toString() for our PrimeNumbers class, even if it infects, it wont propagate and the user wont realize, even if we allready have a wront value thanks to the fault.
For the fourth test, would be the same as the last case, but this time we would use the method toString() causing this to make the user realize about whats wrong in the execution (if it has some of the values to compare with the current result).
Only when the user realizes of this (by the same test result comparation) would be in the reveal stage, if not, it would stay in the propagate stage.
7.- Recode the class using the Sieve Approach, but leave the fault. What is the first false positive, and how many “primes” must a test case generate before encountering it? What does this exercise show about the RIPR model?
If you want to see the exercises’ code in our repository you can visit it here:

In Class Test


  1. Given the 4 @Test methods shown, how many times does the @Before method execute?
    Just one, it initializes global variables. In this case, we are creating objects from the class we want to test.
  2. The contract for equals() states that no exceptions may be thrown. Instead, equals() is supposed to return false if passed a null argument.
    Write a JUnit test that verifies this property for the EH class.

    @Test public void noNPE() {
           assertEquals(false, eh1.equals(null));
  3. Using the given EH objects, write a test that verifies that equals() returns false if the objects are, in fact, not equal.
    @Test public void equalsFalse() {
           assertEquals(false, eh1.equals(eh2));
  4. Using the given EH objects, write a test that verifies that equals() returns true if the objects are, in fact, equal.
    @Test public void equalsTrue() {
           assertEquals(true, eh1.equals(eh3));
  5. Using the given EH objects, write a test to verify that hashCode() is consistent with equals. This test should fail if hashCode() is commented out (as shown), but pass if hashCode() is implemented.
    @Test public void hashConsistent() {
           assertEquals(true, eh1.hashCode() == eh3.hashCode());

How to use JUnit with NetBeans

Hello to all the readers. In this post I’m going to show you how simple it is to test in Java using JUnit in NetBeans. First of all, I would like to say that this tutorial is only going to cover what we need to do to start testing simple programs for the TC3045 class in ITESM Guadalajara, that’s why we I’m going to use JUnit 4. The objective is to show how simple it is to setup the programs and start coding right away. Similar tutorials might be around the web and I’m not an expert on this subject, so if you would like to take a deeper look I recommend you going to the documentation in the official site. Everything in this tutorial is just the steps I did to have everything running in my PC(Linux). I hope you find it useful.

Step 0: Install Java

If you don’t have Java installed all you need to do is to run this commands con your console to install the JavaDevelopmentKit(JDK) in Ubuntu.

sudo add-apt-repository ppa:webupd8team/java
sudo apt install oracle-java8-installer
java -version
javac -version

Thanks to this tutorial for the help. If you are in other OS like Windows I recommend you to do the installation as any normal application, try the official java site for the JDK. Remember that sometimes you have to configure the PATH manually.

Step 1: Install NetBeans

  • Go to the official site of NetBeans and download the newest version.


As NetBeans 10 does not have an installer we must do it manually with the binary files. Download the zip file and decompress it.



  • Do the manual install for the bin files

For this I need you to open the terminal and go to the location of your netbeans folder. In my case I moved it to Desktop.


From here to do the installation insert the following commands:

sudo mv netbeans/ /opt
sudo ln -s /opt/netbeans/bin/netbeans netbeans

The first command moved the bin folder to /opt and the second command created a new command “netbeans” for the console that executes the program.

Now to open netbeans just write netbeans in your console.


Step 2: Create a project and write a java class

Lets star creating a new project. To avoid complications I like to create a project for the whole class and every file and exercise will be in this project.

  • Click on the “New Project” button


  • Select Maven and click next. We want a Java Application in Maven because it’s easier to handle dependencies.


  • Write the project name and choose the location. Then click “Finish”.


Now it’s time to create a class and start coding.

  • Click on the “New File” button and create a new Java Class.


  • Choose the class name and click finish. I’m going to call it Operator because the class will have functions to do simple operations.


  • Code

Now we should have the class in out screen. I’m going to start adding simple function for sum, multiplication and a hello world.

public class Operator {
    public int sum(int a, int b){
        return a+b;
    public int multiplication(int a, int b){
        return a*b;
    public String helloWorld(){
        return "Hello World";

Step 3: Create a test for that specific class

NetBeans creates automatically a testing template for the class you want, all you have to do is to modify the tests or create more.

  • Click on Tools and Create/Update Tests(You have to be on the Operator class)


**Ignore the typo in the picture 🙂

  • Deselect the options on the image(we are not going to need that), and click OK. You can change the name of the new class if you want.


Now as you can see in the new test file all the functions from Operator have a testing function. If we run the tests now it will fail because we have to remove the fail() call and modify the test.  The “assertEquals” at the end is what defines if the test passes, if the two paramenters are equal the test will pass. There are more options to create more specific tests but as I’m covering just the basics I’ll leave the code here with simple assertions that should pass.

public class OperatorTest {
     * Test of sum method, of class Operator.
    public void testSum() {
        int a = 2;
        int b = 3;
        Operator instance = new Operator();
        int result = instance.sum(a, b);
        assertEquals(result, 5);

     * Test of multiplication method, of class Operator.
    public void testMultiplication() {
        int a = 5;
        int b = 3;
        Operator instance = new Operator();
        int result = instance.multiplication(a, b);
        assertEquals(result, 15);

     * Test of helloWorld method, of class Operator.
    public void testHelloWorld() {
        Operator instance = new Operator();
        String result = instance.helloWorld();
        assertEquals(result, "Hello World");

To run the test all you have to do is right-click on the code editor and click on “Test File” or press the buttons Ctrl+F6. The output should be something like this:


For the purpose of the class, this configurations is still not enough because NetBeans 10 uses by default JUnit5 and the book of our lecture focuses on JUnit4. The final step is to install JUnit4. Remember that I said that we are going to use Maven because is easier to handle dependencies? This is the reason, with only a few steps more everything will be ready to go.

  • Add the JUnit4 dependency.

For this you have to find the file pom.xml and open it.


Now inside the <dependencies> between any dependency add the next chunk of code:



Save the file and then wait for the automatic installation.

  • Change the import of the tests.

Check the imports of your test file, it’s using the library for JUnit5. All is left to do is to use the imports from JUnit4. Remove the import lines and copy paste this ones:

import static org.junit.Assert.assertEquals;
import org.junit.Test;


Now it’s all done!!

You are ready to go try your own classes and tests. If you want to learn useful tricks to do the activities check out this file, where you will learn to handle exceptions in testing. Remember that sometimes it is expected that the code fails, this tests are useful to test edge cases and avoid weird inputs.

If you want to see the sample code in GitHub here is the link to our project repository. It’s on a separate branch because is not related to the main testing, but it’s good to have samples somewhere in case we need them.

I hope this tutorial was helpful to you. Feel free to share this content or any content referenced here to help others as well. Keep learning and have fun.