Ain’t Nobody Got Time for That…

ANGTFT

Sometimes you do certain tasks that become normal and you kind of go into autopilot, blindly repeating the same thing over and over again. It normally takes someone else or something else to spark something in your mind and give you an idea that there is always a simpler solution.

My spark came in the form of Alan Richardson, I’ve been a huge fan of his work for a while and I love the content that he creates and the weekly YouTube videos! A couple of weeks ago he released a short video about creating a bookmarklet to change some static text URL links on a web page, into actual clickable links, that open up a specific web page, a Twitter profile in this case. I thought that was really cool and looked like something that I could have a go at myself. All of the JavaScript code for doing this was written within the Chrome DevTools console – Perfect, I’m familiar with these already!

Recently, I’ve been using a strategy when testing, that involves creating “Test Queues” within RabbitMQ (The message broker that we use for our microservices) that siphon all the messages from the queues that our microservices are consuming – The Test Queues hold/store them, so that I can investigate deeper into the message data. Unlike the actual queues, these do not have consumers so the messages will stay there until I choose to delete them, adding an extra layer of control. I could just manually stop the service and grab the messages from the service queues but I like to give myself a separate option.

Screenshot from 2017-06-03 11-13-34
RabbitMQ – Publisher > Exchange > Queues > Consumers…

For context – My Test Queues would live alongside the red ones in the image above but will not have consumers, the arrows to the right of the red queues…hopefully, that makes sense. 🙂

My boring repetitive problem…

RabbitMQ is an awesome message broker and like it says on the site “Messaging that just works” what they haven’t concentrated on is the usability of their UI management console, why should they, that’s not their main focus – they currently just have something that’s good for now. As much as having these queues is really useful, clearing them out or purging them is a tedious task, it’s made worse by the fact that I follow the same process several times a day…

Click on the queue name > scroll to the bottom of the page > Click on the “Purge” button > scroll back to the top of the page > Select the Queue tab to get back to the main view…repeat…yawn!

I’m a fan of getting a local instance of the technologies that we use within our feature team and exploring lots of different aspects so I feel more comfortable and more informed about the tools I’m working within. I knew the RabbitMQ has a HTTP Restful API with a limited amount of features, I can use some of these to my advantage!!

RabbitMQ has been around for about 10 years now so I had a hunch that someone has probably had the same problem as me and wanted to use the API to purge the messages within a queue…I headed over to Google…

Basically, the first result that came back was about 90% of the solution that I required…Bingo! I found this from 5 years ago – Like I said, it wasn’t exactly what I wanted so I needed to adapt the code to suit my requirement.

I grabbed the code and pasted it into a new Snippet within the “Sources” tab on the Dev Tools, I love this feature, it’s like a little playground for practising and running basic JavaScript. The code in the gist deletes the messages from every single queue which was the main part that I needed to change, I tend to apply a simple naming convention to my queues and prefix them all with “TestQueue_” – This is just so that they are all grouped together within the management console.

TestQueues_RabbitMQ
My Test Queues with lots of lovely messages…

I only needed to refactor the code slightly and add an IF statement that checks to see if the queue name starts with the “TestQueue_” name if so, purge the queue. All the other queues are unaffected. Job Done!

RabbitManagementConsole
Slightly refactored code with an IF Statement…

During the testing of the code, I added some logging just to sanity check that I was getting the correct queues that I wanted and discarding all the other ones. All the “null” entries below are queues that do not start with “TestQueue_” so are ignored.

Getting_Queue_Names
Iterating over all the queues to get the ones I want…

Once the Snippet was run, I could see that the correct requests are being made…Yay! The messages were deleted from only the queues I wanted.

Console_Output
Console Output showing the DELETE requests…

I have created a gist of the code that I used to Purge the Queues – https://gist.github.com/DannyDainton/2bae06e3ca898440cdc0452a727ee7bf

I could have just settled for that solution and ran this script from the Dev Tools each time but I wanted it to be even easier for me (I’m very lazy) so that’s where Alan’s bookmarklet app comes in handy, you can take any piece of JavaScript code that you have coded to do something on a page and it will create an encoded link that you can add to your browser bookmarks.

Bookmarklet App
Creating a new bookmarklet with my JavaScript code…

So I now have a link on my browser that saves me the pain of going through the tedious repetitive task to purge each queue. It’s the simple things in life that make me happy.

Alan wrote a post to accompany his video that references lots of links about how others have used bookmarklets. One of those is this excellent blog post by Abby Bangser, which I read a while ago before I saw the YouTube video. She explains how she utilizes the bookmarklets to quickly fill in form data – It’s really interesting and I would recommend trying to give it a go yourself.

Hopefully, that has been interesting enough to spark something in your own mind and attempt to give this a go – I would love to hear from anyone who has created a bookmarklet to solve a problem.

Cheers!

30 Second APIs…

In the UK we have a chef called Jamie Oliver and over the years he has created lots of TV episodes and also a book on how to make a complete family meal in 30 Minutes – The premise of this, is that time doesn’t have to be an excuse not to make healthy food for the family.

30_Min_Meals

Now, if you’ve ever seen these episodes or tried to follow this, it takes a lot longer than 30 minutes!! It’s more about a “mindset”, which is a lie, it’s about having everything prepped and ready to go so all you’re doing is cooking the food and not chopping things up and getting the pots and pans ready.

So what does this have to do with APIs?!

In my current context, making requests to a RESTful API and analysing the response data is something I’m perfectly comfortable with doing but that’s only because I’ve been working within that space for a couple of years now. I truly take for granted many of the skills that I’ve learnt over the last couple of years and I forget, that you need to start somewhere, in order to build up your knowledge of a certain area.

There are loads of public APIs out there that you can use but these can be tricky to set up. In my experience, most of the documentation that comes with these is confusing and sometimes it’s lacking vital information. Another way forward is to create your own basic API but this can be a daunting task coding it yourself, although a very rewarding once you get it working!

What if there was an even easier way that would allow you to have control over the requests that you make and the data that you want to see in the response?!

I’ve found this node module called json-server that is very handy and super quick to get you started. It’s only a couple of commands from a terminal and you are up and running and making requests within seconds….seriously!

The 30 second API mindset…

So following Jamie’s lead, before starting we need to do our Mise en place…We require a couple of things in place before we get cooking.

Prep Work:

  • Download and Install Node.js
  • Download and Install Postman
  • Create a new Folder on your machine
  • Open a Terminal in the new directory

Your starting point should look something like this – depending on your terminal/Postman colour preferences…
Starting_Point

First of all, we need to globally install the json-server module. In the open terminal, type the following command:

npm install -g json-server

Once this has been installed you’re basically ready to make requests. Quick right?! As you have installed the module globally (using the -g flag), the server can be started from any directory but we will be using our newly created one.

In the terminal, type:

 json-server db.json

json_server_db_file
As you do not have a db.json file in that directory, it will conveniently create one for you and populate this with some default values. These are good for now, just to get you started and making basic requests. Later in the post, we will talk through how to create data files containing the data that is more relevant to your context.

We’ll be using Postman to request the data from the db.json file but it’s entirely up to you, use something that you feel comfortable using. You can now send a request and get a response containing data from the file. The available routes are displayed in the terminal, you can use either of these routes in your first request.

Copy one of the routes below and paste this straight into Postman, you will get the data returned from that Endpoint.

 

GET_Request

Sending a GET request is easy right, the best thing about the json-server module is that it gives you the ability to also practice sending POSTs, PUTs and DELETEs. I would attempt go through each one of these methods but the documentation on the json-server GitHub page explains these methods better than I ever could. This also covers a number of awesome features that you can make use of when using the application.

I don’t want to use the Default data file…

Fear not, as this is essentially just a JSON file that you’re using, you can have any data you desire. You’ll need to stay within the applications format for the way it parses the routes/endpoints from the .json file but apart from that, it’s up to you!

I’ve used mockaroo to create some random data. You can grab this from here and save the .json file to the same directory. Stop the current server instance (Ctrl+C) and spin up a new one using the new dummyUsers.json file:

json-server dummyUsers.json

Requests can now be made to access the new data – Try a GET request to http://localhost:3000/users or how about selecting just one user http://localhost:7000/users/{id}

Request_Single_User

Handy Extras…

If like me, you have applications running on certain ports on your local machine, you will need to either stop that process or give json-server a different port to use. This can be done from the command line before you start the server:

json-server <file.json> -p <port number>

When making changes to the .json file manually in a text editor you will need to stop and start the server instance that you have running, for the changes to take effect, which obviously sucks because you want to be able to see your changes straight away. Luckily, there’s a command line flag to get over this:

json-server –watch <file.json>

Any manual file changes made will be automatically detected and the server will be restarted for you and you’ll be able to continue making those lovely requests.

To Finish Off…

So that’s it, you now have a platform to practice making requests to an API that you have control over and all without writing any code. I’ve only covered a small part of what json-server offers during this post, I would advise you to have a look through the GitHub page once you’re comfortable using the basic function of the application because it offers so much more.

Good luck and let me know if you find this useful. If you have any questions just drop me a message!!

An Extra Helping…

I’ve added some more information about using a collection within Postman to make different types of requests and interact with the dummyUsers.json data. Hope it helps!!

https://github.com/DannyDainton/API-Postman-Practice

Bringing external content in-house…

Being an active member of the test community, I sometimes don’t appreciate how difficult it must be for other, not as involved testers, to find great resources outside of their workplaces.

I have the benefit of knowing or being aware of certain prominent testers who write about topics or have a specialist area that they tend to blog/talk about – it’s easy for me to say “he’s blogged about that lately” or “she’s spoken at a conference about that topic recently” and straight away I have an entrance point, so that I can expand on an idea I may have and go from there to move things forward.

I’m probably one of the only people left in the test team at NVM that is always on Twitter or watching conference talks etc. People learn in different ways and subscribe to other channels to get their testing information – I get that, it’s a personal learning and development thing. What I wanted to do is expose/share some of the great resources that I love, with the test team, in a not so “in your face” way. I didn’t want to push anything on other people, that they didn’t want to read or watch so I set up something that they could tap into or look at if they have some spare time.

So much to choose from…Where do I start?

There really is so much content out there, that I could absolutely flood my team with lots of blogs, articles and videos but I don’t think that would be useful and could potentially have the opposite effect and scare people away. I started with 2 resources that pack a lot of items in a couple of links.

I saw this tweet from Katrina Clokie where she mentioned one of the resources I had in mind, I love that see was recommending people to follow the Testing Curator!! I’ve followed this account for a while, as it really is something special – well worth subscribing too!! Great job Matt!

 

katrina_tweet
Go and follow @testingcurator

 

 

Making the content easily accessible…

I’ve blogged in the past about using Hipchat at NVM, although some people may prefer Slack, this is fine for us and suits our current needs. Hipchat has an API, like many other platforms, that allows you to send messages into “rooms”. Our Test Team has its own room where we can exchange test ideas, test improvements, new things that we’re learning etc. This seemed like the perfect place for these new testing resource feeds. As well as the Testing Curator feed, I’ve added Simon Schrijver‘s 5 blogs feed. This is excellent and provides the team with 5 new blogs to read each day! Thank you so much for providing this service!! I love that the blogs are not only about testing, it’s a great mix!

 

hipchat
Hipchat messages

 

 

A Helping hand…

Although I’m loving coding little applications at the moment and I could have attempted to do this from scratch but…I thought “What’s the point?!” I would have either epically failed or it would have taken me too long to achieve. I’m a huge fan of integration services like Zapier and IFTTT – they are just really simple to set up and so useful for what I wanted to do. I’ve chosen Zapier for my integrations, I love that it has really intuitive UI and you can test each step as you go, so you can clearly see what’s happening.

This is an example of the 5 blogs “Zap” that I have created, It’s triggered by a new item on the RSS feed and then sends a configurable (see image below) message to the Hipchat room. Simples. The task runs every 15mins, looking for changes – there are different account plans that you can have on Zapier but the free plan is sufficient for what I have it set up to do.

 

zapier_hipchat_integration
5 blogs Zap

 

 

message_configuration_
Configuring the Hipchat message

 

So that’s it…Something that is extremely simple to set up and has hopefully provided my fellow testers with additional testing knowledge. I’m not forcing people to click on the links and read the blogs, it’s all there if they want to take a look.

These integrations can be set up on Slack, etc. in exactly the same way so if you would like to provide your team with some excellent content I’d recommend taking a look. Once it’s set up, it’s going to just run in the background.

I would love to hear if anyone has a similar sort of thing set up already and how it went down with the rest of your team.

Cheers!

Hipchat Custom Commands – Continually Improving our processes!

At NewVoiceMedia, like many companies, we hold Hackathons each quarter. This is a chance for everyone (not just developers) to create something that will be of benefit to our customers or help improve an internal process of the business. These small projects could be a proof of concept or a small feature that is ready to go straight into the Live product.

In the past, I’ve helped out on tiny projects with a couple of developers but for the last few hackathons, I’ve used it as a chance to improve my coding skills and create tools to help out other people. There has been a process that has bugged me for a while and we do the task every week, so I thought that it was a perfect place for improvement. We manually create/construct a URL that displays the release notes for our service, based on the “start” and “end” commit numbers, the “start” number being our deployed production version.  Like I said, this is a weekly task as that’s our current release frequency. I knew there was a better way and more efficient way to get this done. The URL in the images below is an internally used NVM address so it, won’t work anywhere outside of our Company.

A while back I read a great post by Neil Studd, He created a bot that was accessed via a custom slash command within the Slack platform. I thought it was impressive and it was something that I wanted to try to replicate myself! So I had a slight problem at the very beginning, we don’t use Slack at NVM (not my choice), we use Hipchat instead. I needed to figure out how I could get a custom slash command to work with that platform, thankfully, they do have their own version of this feature.

Similar to Neil’s method, I wanted to use Heroku to host my application, I mainly wanted to try this out because it was unfamiliar to me and it was a great opportunity to learn something new!!

Creating an MVP

I’ve recently been dabbling in NodeJS and creating little test tools that I use on my team, we also have a production API that uses this language so I’m quite comfortable in that space at the moment. For what I wanted to create, it was a perfect choice. I created a tiny Node Express app with a single POST “/notes” route, this was going to be the entry point from Hipchat. Once I got those two things hooked up and talking to each other I was sorted – because I’m a noob and couldn’t understand the Hipchat API Documentation fully, it took me bloody ages to figure out what was being sent from Hipchat and how I could grab that data to then start the next phase.

I found a video that really saved my skin and allowed me to move forward, the demo video used a tool called Requestbin that gives you a URL for Hipchat to POST the ongoing request. The Requestbin site then just displays every single piece of information in the request!! I was in business and I could navigate through the JSON, in the body of the request to get what I required.

Now that I had what I needed, I was able to use some Node modules to do most of the donkey work and get a working solution up and running quite quickly – At this point it was quite basic and very buggy, I think I broke it on the second request that I made to the application. I wasn’t actually thinking like a tester during the coding part, I was just trying to get something working. I actually don’t know why I didn’t plan and approach this like I would a normal project but you know, you live and learn.

 

mvp
My MVP

 

Bringing a tester onboard….

I needed to put my tester hat on and actually, think how I would use this application from a consumers point of view. I made a short bullet point list of possible ways that I can think that someone might use the tool or possible edge cases that I can mitigate against.

  • Entry point
    • /notes (I wanted this to be the only entry point)
    • /NOTES (I didn’t want this to return anything)
    • /NoTeS (I didn’t want this to return anything)
  • What could the user enter?
    • /notes valid number (/notes 12345)
    • /notes without a number
    • /notes number of digits (1, 2, many)
    • /notes and repeatedly entered 5 digit strings (/notes 12345 12345 12345)
    • /notes position in the sentence (“some words /notes 12345”)
  • Is the returned URL in the message a hyperlink? (Hipchat API auto picks up links, if in the correct message type “text/HTML”)
  • How do the other built-in slash commands behave (/code etc.)
  • What happens if the external GET resource is not available or returns the wrong data?

These are some of the questions that I was asking myself, I had many more but this is the general gist of the ideas in my head. The whole time that I was making changes to the code and then testing the outcomes I was thinking that I wanted to add something that would let me know what was going on behind the scenes of the application when the users were making requests. We recently had Richard Bradshaw come into our company to deliver his awesome Lego automation workshop, in this he mentioned “Giving your automation a voice” – This wasn’t test automation but I did want to know what was going on, it was only going to tell me if I actually told it too. I added log messages to the application at key points so that I could track what was actually happening rather than just seeing an output in a Hipchat room.

 

app_logging
Giving It A Voice

 

Another approach I was thinking about while testing was Ben Simo‘s FAILURE mnemonic if users were entering the wrong information, I wasn’t telling them (oops), It just didn’t return anything to the Hipchat room. That didn’t sit right with me and I used Ben’s heuristic to guide me, I wanted to give the users some feedback and let them know that “Something wasn’t quite right” with the data that they had inputted. As I could tell which Hipchat user sent the request, I grabbed that information from the JSON and made my returned messages (both good and bad) a bit more “friendly”. Manners don’t cost anything, as my Mum used to tell me.

 

release_notes_helper
Making It Friendly

 

error_handling
Appropriate Error Messages

 

Finding bugs in the wild…

I wanted to add an additional feature for users to specify a different environment when making the request (e.g. “/notes 12345 cloud4“), I initially defaulted the response to our main production node when users entered “/notes 12345“, as this matches the current behavior of the main internal release notes creation tool. I wanted to be a little bit more flexible, I had the opportunity to add extra functionality and let the users decide what the returned data was going to be. I added the code and rushed through the change, “It worked” so I left it and communicated out the new feature, giving an example of “exactly” how this worked. Great success! Maybe not…

 

cloud_request
Location Matching Feature

 

I’ve used Regular Expression in a number of places to capture certain things, I’m new to using Regex so I had a little help from the Regex101 site and also practised some of the Regex in the Chrome Dev Tools console (This was super useful!!). It turned out that my Regexfu is not so good and I omitted the “i” from the expression. meaning it was case sensitive so if someone entered “cloud4” it would return what they thought it would but “Cloud4” and “CLOUD4” wouldn’t return the same thing. From a users point of view, you would still get back a valid URL as it defaulted to a certain value if you didn’t enter exactly “cloud4”. I’ll get back to this issue.

Logging and Monitoring…

Using Heroku, I could access their built-in raw logs and could see what was happening while people started using the application. These were great and showed me what I wanted to see, the only trouble was, I had to go on to the Heroku site each time. At NVM we use Papertrail and I know that I could bolt on this log management tool to my Heroku app and feed the log messages into there. Great, I know this app and the search syntax so I was sorted….not quite, because we use in at NVM it annoyed me that I had to login and logout each time I want to see either the work logs or the ones that my app was producing.

Up stepped LogDNA – it was another option from the Heroku list, so I gave it a whirl. Luckily, the search syntax was very similar to Papertrail and it was extremely easy to get it set up in the way I wanted. It also had a feature where you can set up a notification on certain searches so that you get emailed when things start going wrong or just have something that lets you know who is using the app.

 

email_notification
Email Notification

 

Coming back to the Regex bug that I found earlier, I basically only saw this because of the logging that I had in place. I could see that a user had made a request, that should have failed (in my mind) but it returned the default value. I was able to spot the issue, fix it, test it and then deploy it again in super quick time without it impacting the users. Testability win!

Distribution…

I’ve now added this app to multiple Hipchat rooms and I’ve seen the usage steadily increase, which make it all worthwhile. I’ve also created an internal wiki page so that people can add it to any Hipchat room and it also explains some basic instructions with examples.

As well as doing this internally, I’ve knocked up a very simple bare-bones node app and placed this in a Github repository for anyone to use/rip apart etc.

You can grab the code here: https://github.com/DannyDainton/node-hipchatbot-basic

That was an epic read but hopefully, it makes sense and encourages other people to give things a go and try and improve a process that annoys you too!

Cheers!!

Everyone loves a bit of Bug Magnet!

I’m still in the random data creating mood, so I thought I would extend my last post slightly by showing / explaining how you can quickly add some of the random data that you have created, into Bug Magnet as a custom config file.

If you haven’t heard of this Chrome and Firefox extension…where have you been?! I’m a huge fan of this tool, it’s assisted me during numerous testing sessions since I discovered its existence.  A while back, a new feature was added allowing you to add your own JSON files  – This was a game changer for me, It allowed me to create lots of different custom files specific to my context, for me to use whenever I needed too. Adding and Removing Files is soooo quick and easy that it really makes having something this valuable in your testers toolbox, an absolute no brainer.

A better explanation of what you can do with Bug Magnet can be found here. Neil Studd is extremely good at walking through how you can/could use the tool.

Let’s extend what we have already…

Open a command prompt or terminal, in the directory where you saved the random-data-generator app (Go and check out my last blog post if you’ve forgotten already). We’ll need to bring in the jsonfile module to our app, this will help us create the file that we can use with Bug Magnet.

Type the following command and press Enter. This will install the module and also add it as one of the dependencies in our previously created packages.json file.

npm install --save jsonfile

install_jsonfile

Once that has finished installing, it shouldn’t take very long, create a new file and save this in the random_data_generator directory. For this example, I’ve named the file cardDetails.js. As you can tell by the name, this will create some random payment card details.

Add the following code to the new file:

// Dependencies

var casual   = require('casual');
var jsonfile = require('jsonfile')

var file = 'cardDetails.json'
jsonfile.spaces = 4

// Random Card Data Set

casual.define('cardDetails', function() {
 return {
     Name        : casual.full_name,
     Card_Type   : casual.card_type,
     Card_Number : casual.card_number(casual.card_type),
     Card_Expiry : casual.card_exp
   };
});

// Write the result to a json file

jsonfile.writeFile(file, casual.cardDetails);

Like before, I’ll briefly explain what’s going on here – At the top we are bringing in the modules, casual is our random data helper and jsonfile is the module that’s going help us out with creating the JSON file (Say’s it all in the name really). Next, we have the file variable and this, as you would have guessed, is where we are naming the output file. At the moment this is just getting saved to the root directory of the app but you can specify a location anywhere on your system if you like, entirely up to you. Just down from this is the spaces that you would like to set, I’ve set it to 4 on this occasion as the default value is null and 4 gives you a lovely pretty print feel. Have a play about with it and set what you think is right.

In the middle of the file is the meat of the operation, this is creating your random data. Previously, we used user data and saved this in the user.js file, I’ve just mixed it up a bit and used a different data set. Lastly, we have the line that will write all the output to the JSON file.

Time to create the JSON file…

In a terminal, type the following command and press Enter. This will do the business and create the JSON file.

node cardDetails.js

create_json_file

You should now be able to navigate to the file, in the location that you set in cardDetails.js and it can be opened up in a text editor.

The cardDetails.json file will look something like this (with different data obviously).

{
    "Name": "Kristopher Hickle",
    "Card_Type": "Visa",
    "Card_Number": "4485446830945271",
    "Card_Expiry": "04/17"
}

Add the file to Bug Magnet…

I’m assuming that you have the extension already installed, if not, go do that now.

In the Chrome browser type chrome://extensions/ into the address bar and press Enter, Select the “Options” button on the Bug Magnet extension. 

Select the “Add Configuration File” button.

bm_add_file

The Name that you enter in this field, will be the name that appears within the context menu in Bug Magnet, next to the default ones (Names, Cities, E-Mail addresses etc.).

bm_name

Press the “Select File” button and navigate to the cardDetails.json file. Select the “Open” button and this will then add the new config file to Bug Magnet. That’s it, it is now ready to be used in anger against the site you’re testing.

We’re now done – I’ve taken you this far, it’s now up to you to create the data and start using it in association with Bug Magnet.

To finish off…

These guides are obviously very basic and full of potential problems, I can see loads myself. They are not intended to be perfect, I view them more as a helping hand to get you started. Even if you don’t follow my method of creating random data, please do go and check out Bug Magnet – The default data that comes with the extension has found me so many bugs over the last couple of years!! At NVM, we have created our own repository of JSON files that is in a shared location, these can be tapped into and used by anyone, not just testers. All we need to do is import them into Bug Magnet before a test session and we’re set.

I created a really poor set of instructions for my team on how to create these custom files (using manually added data) a while back – you can find them here.

I’m still learning how to use GitHub and I continued my learning by trying to add all the files I’ve mentioned in the blog posts to a new repository. I think I sussed it but there are a few dodgy commits on there – Feel free to take a look here.

I’ve enjoyed writing these, it helps cement in my mind what i know and whIt i need to improve on, thank you for reading!!

 

My own personal Testability experiment!

Two weeks ago I decided to focus my learning on a particular area each month, historically i’ve been rubbish at concentrating on one thing. Testing is so vast with lots of different interesting areas to research it can become a little overwhelming at times. Something had to change for me:


I wanted the choose a subject that i was aware of and what I thought i knew it to be but i was never too sure about how wide it stretched. Testability was going to be the main focus!

I had a basic plan in mind – Split the month into two parts. The first 2 weeks will be research and observation (My team and the wider Test Team) and the second 2 weeks will be trying to implement some improvements or make improvement suggestions. The test community has massively helped me during the research phase, there’s many great things that have been written about Testability over the last few years and these normally reference other articles or conference talks so it’s actually been a really enjoyable experience discovering a bunch of very interesting things.

Here’s a list of the Blogs, Articles and Talks that i’ve read over the last two weeks:

Blog Posts

Articles

Models

Conference Talks

It’s going to be an interesting couple of weeks coming up, I’m planning doing a follow up post when the time is up to explain what worked and what didn’t work. I’ve had a lot of fun concentrating on one area, i’ve slipped up a few times and wondered down different paths but i’ve been focused enough to indentify these lapses and then got on track.
Huge thanks must go out to Huib Schoots – His Great Resources page was the starting point for my research.

Does anyone else take a similar approach to their learning or maybe you have a different method? I’d love to hear about it!

Creating Random Data on my Lunch Break…

A few days ago I read a great post by Alan Richardson called “How to write a simple random test data sentence generator” and i loved it, it’s exactly what I try and do all the time. In my current context, data is king, without data flowing through our service we effectively have no service. While testing stories, I create tools that do loads of little things but I have a selection of ones that create specific test data. Now, I’m not a developer, I don’t have any sort of development background but what I am, is an inquisitive learner.

I love writing code, not because I’ve been made too or I’ve been told too by my company so that I can automate all the things, I do it because it’s fun! I get a massive sense of achievement when I’ve had an idea for a tool, wrote some code and it’s worked!! It’s not the best looking and most efficient code but it’s my code and i’m proud of it!

So where was I, the random data generator – I read Alan’s post just before lunch and just before i tucked into my food i wrote a very basic app that spit’s out random data. All in all it took me less than 5 mins, it was done as a kind of exercise to prove that absolutely anyone can code something that creates test data. Don’t be afraid of just giving something a go, you might actually surprise yourself!

*This is wrote using Node.js but there’s probably tons of modules and libraries in your preferred language that will allow you to do the same thing*

We need to start somewhere…

In order to get your hands on this random data you’re going to have to download Node.js it won’t take very long and it’s so worth it, not only for this but for many other awesome things that you can create using Node.

Once you have it installed, type node -v into a command prompt or terminal. You should be presented with the current version that you have on your machine. If you’re not seeing the version, don’t panic, you might have to add the node directory to the path environment variable. You’ll find loads of step by step guides for this if you Google it.

node -v

node_version

Let’s do the code part!

So first things first, we need to create a new directory for your new and wonderful data generator to live. Open a command prompt or terminal (you may have one still open) and enter the following commands, as seen below. It’s entirely up to you what the root directory should be, after all, you’re doing this on your own machine.

mkdir random_data_generator
cd random_data_generator

*You don’t have to create this but I just like creating it so that i can give the app to other people*

Next, we need to create the package.json file this is the config file for your node app, it lists all the dependencies that you have in your project and also a bunch of other stuff you may need to add, as the app starts growing legs. You can read all about what this file is and what it does here but for now, we’ll crack on…

In the terminal enter the following and press Enter. Press enter through all the questions and type Y or Yes at the end.

npm init

Now we have that json file created we need to bring in the node module that’s going to do all the leg work for us and create the random data. Casual is a great helper module that rapidly speeds up the process of creating random data. There are a couple more great modules out there that do the same thing, like Chance.js and Faker.js but were going to use Casual this time because it’s the first one I thought of and I’m writing this post so that’s what you’ve got!

Install Casual by entering the following command into your terminal and pressing Enter. The –save in the command adds this module to the packages.json file, honestly, go and have a look if you don’t believe me.

npm install --save casual

When it has finished installing the module, leave the terminal open as you’re going to need it in a few mins.

Create a new file with your favorite text editor (Sublime Text, Notepad++ etc.) and save this in the new random_data_generator directory. For this example, I’ve named the file data.js but you can choose a name that’s more relevant to you.

In the file add the following code…

 // Dependencies
var casual = require('casual');

// Using the module to create random data
var number = casual.array_of_digits(n = 4);

var name = casual.first_name;

// Log the result
console.log(number);
console.log(name);

There are a couple of things going on here and I’ll explain (probably really poorly) what they are, so starting from the top, the first line after the comment brings in the Casual module so that we can use all of that goodness. Next, in the middle section, we’re using a couple of the in-built Casual functions that will create the random data and assigning these to the variables. Finally, we are just logging the output in the console. Very basic and extremely simple.

Using the terminal that you previously opened, type node data.js and press Enter to run the command. If everything has been setup correctly, you will be presented with some random data. It’s as easy as that.

data_output_02

 

If you create another file in the same directory and save this one as user.js I can show you a simple way of creating a set of basic user data. Add the following code below to the file and hit save again. To get an idea about what you can do with the Casual module, check out the documentation.

// Dependencies
var casual = require('casual');

// Custom Data Set

var password = '#A#B#C#D#E#F#';

casual.define('user', function() {
 return {
 Firstname: casual.first_name,
 Lastname: casual.last_name,
 Password: casual.numerify(password)
 };
});

// Write the result to the console

console.log(casual.user);

What this file is doing is creating a data set, defined and configured to your needs. Using the define function of Casual you can package this all together in a lovely little ball and do what ever you like with the output. On this occasion, I’m just logging it out to the console again. There are a few other things happening in this data, i’m using a couple of other inbuilt functions to create a different (very rubbish) password.

In the terminal type node user.js and press Enter to run the command. There you go…some more data for you!

data_output

Where do you go from here…

As you can tell this is very basic and the only thing it really does is print data out to the console – Not that helpful. This was only ever a 5 min task to quickly knock something together, we can expand this out to push the data to a certain file format that your system uses or feed the data into an already established test tool that you have been manually creating random data sets for, etc etc….I like the idea of creating Json files that can be added to apps like Bug Magnet so that you have the data there for you, while you’re doing an exploratory session.

We are only ever limited by our own imagination so it’s entirely up to you where you go from here but i’d love to hear about it so drop me a message!

*If you really can’t be bothered to create a tool yourself – Just Google “Random Data Generator” there’s bloody tons of them knocking about!!

Cheers for reading!

I now have a follow on post where you can put some of this beautiful data to good use…https://dannydainton.com/2016/09/28/everyone-loves-a-bit-of-bug-magnet/