Software Testing

Recently I’ve been working a lot with Java Projects. As a part of my development work I’ve also had to work with both performance and automated build tests that run for a project.

Testing is great for maintenance and the life of a software application. If you setup your tests correctly, it can make additions and new development easier.

Tests can come in many forms to include unit tests, regression tests, performance tests, and acceptance tests.

Typically as a developer you write unit tests as you work along on your project. You develop a class or set of classes and write unit tests to verify that what you’re writing works. Historically, most developers do this after the fact and don’t really put a lot of effort into this. They test because they have to, its a requirement from the customer etc. In truth these tests are just as important as the work that is being developed. These tests will ensure that future work does not break previous functionality (regression tests) and they can ensure that what is written actually functions without having to actually use the application.

There is an entire methodology of development called “Test Driven Development” which actually gets you to write your tests first and then build your code around it. If you do a quick Google search of test driven development you’ll undoubtedly come across “Uncle Bob” and his videos. Uncle Bob is Robert Martin, he’s a Software Engineer thats done a lot of talks and presentations that really focus on best practices for software development. Here’s his wiki page Uncle Bob’s videos are really good and give you both perspective and an intro to what you could do if you follow this methodology.

Here’s an Uncle Bob video from YouTube:

So back to my central point in this post, testing.

Testing can be categorized into several forms. I’m going to mainly talk about Automated Tests and Performance Tests here.

Automated Tests

Automated tests are great for development. Its as simple as that. If you have automated tests then whenever you make changes to your project you can make sure that your new code does not break your old code. This makes development easy and saves you the time of having to manually test a lot of older functionality in a large project. Obviously a smaller project probably wouldn’t require this, but its just a good idea to do it.

There are lots of tools that you can utilize for automated tests.

Most of the time some quick google searches on automated tests will point you to Selnium Webdriver. Webdriver is a very robust set of tools that work for both the frontend and backend. They typically work by creating a mock browser session and running your code. It could also just run a session of your web app that interacts with services. Here is a link to Webdriver

Frontend developers typically would have something setup with Protractor. Protractor works great with both Cucumber and Jasmine frameworks. If you do some quick google searches you can find a lot of how to articles. Cucumber is older and so a lot of the posts you’ll find are outdated. If you’ve never heard of this, the basic process is that you have an instance of selenium webdriver running Protractor. Protractor uses chrome headless (or whatever framework you pick) to create a mock browser. Then Protractor will use steps and features that you’ve written in either Cucumber or Jasmine syntax to run through the browser as if you were a user. There is a huge amount of flexibility here, and it allows you to basically mimic a user with your application. Its pretty cool and well worth checking out. Here is a link to Protractor

Additionally with backend developers they would typically use a cucumber test runner setup. For example, if you had a Java Project using cucumber you’d have the following:
1. Cucumber Runner class (actually initiates the tests)
2. Feature File (what the runner reads to run the tests)
3. Step Class (runner reads the feature then runs the steps defined in code here)

There is a nice GitHub project that you can look into for setting it up with Java here

Performance Tests

Performance tests want to test the capabilities of your application. Example of this could be seeing how it reacts to traffic, multiple processes, timeouts, large files etc. There are several frameworks that you can utilize to do performance tests. A good example would be the Java based application JMeter.

JMeter is a very basic utility which enables you to setup processes that can run and report on performance metrics. The process of setting up JMeter to test your application is basically the following:
1. Create a “Thread Group”
2. Create an “HTTP Request” for the thread group
3. Setup a way to view the results (typically in a table)
4. Determine setup time for your tests (if you have several processes running this typically would be longer to account for thread creation and destroying etc.)

The cool part about JMeter is that you an run it both locally and as part of your Continuous Integration Continuous Delivery (CICD) pipeline. So you can basically set this up to run whenever you make changes (and do a build) for your project. If you want to learn more about CICD check out Atlassian’s write up here (not working for atlassian they just give a good writeup here 🙂 )

Here is a good link to JMeter

One other cool thing that I wanted to share before finishing this post. So when you do testing a lot of times you need files. I worked on a recent project where I had to test large files and needed a way to make files a certain size (5MB, 10MB, etc. etc.). There is a cool way to do this with the terminal if you use a unix or linux machine and use the command “mkfile”. Example <

mkfile -n 10m large_file.txt

The syntax is just

mkfile -n <file_size> <file_name> 

It lets you create large files that are empty, but are good to use with performance tests.

Hope this post helped you to understand testing better and (if you are a developer) gave you some links for improving your day to day work.


2 thoughts on “Software Testing

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s