Category Archives: Week 9

Stubs, Mocks and Service Virtualization

We’ve been discussing the differences between stubs and mocks, along with the fact that many software testers may initially assume the two are the same concept. But as we have learned, mocks and stubs are not synonyms; they are two different techniques used within unit testing.

I wanted to learn more about some specific differences between stubs and mocks, such as potential advantages and disadvantages of using each of these techniques. Wojciech Bulaty has an informative article on the subject. Before getting into the pros and cons of each aforementioned technique, Bulaty explains the main concepts of stubs, mocks, and service virtualization.

He asserts that stubs use hardcoded data within the testing program itself, where the tests depend on this data. Based on Bulaty’s description of stubs, it seems it would be most beneficial to me to apply stubs when testing simpler code where no more than minimal implementation of an interface is required.

Mocks on the other hand seem to be most useful in situations for larger, more complex tests to “verify output against exceptions.” In my opinion, mocks ought to be used in addition to stubs to further satisfy the integrity of our testing. For instance, mocks may produce findings that stubs could not, due to the limitations of the hardcoded data within stubs. On the other hand, I feel it may be useful to use stubs as well, to help compare its findings with that of the mocks within our tests.

Bulaty introduces a third method to use within our unit tests: service virtualization. I found this particularly interesting because we haven’t discussed much about service virtualization in class yet, and this article helped me learn more about it. He explains that service virtualization supports testing through multiple protocols, and employs “test doubles” which are usually offered as Software as a Service (SaaS). It seems to me that service virtualization relies more on recorded data from a wide scope of different projects, whereas stubs and mocks are typically written by developers of their own projects.

My main takeaway from this article was recognizing some differences in particular between mocks, stubs, and service virtualization that were previously a bit unclear to me. Whereas stubs seem to concentrate on state verification, mocks tend to be more focused on behavior interactions within our code. I also learned which testing techniques may be most appropriate in regards to the particular code we are testing. For instance, if I am testing simpler tests with limited resources, based on what I’ve learned from this article, I will likely use stubs for my testing. But for larger, more complex tests, I feel I ought to implement mocks within my testing as well. Finally, when I am involved in large scale projects during my professional career, Bulaty’s article has convinced me that I should look into using service virtualization in addition to stubs and mocks when performing unit testing.

From the blog CS@Worcester – Jason Knowles by Jason Knowles and used with permission of the author. All other rights reserved by the author.

B9: Chain of Responsibility

Chain of Responsibility

      This week I chose to write about a blog that talked about the behavior design pattern known as the chain of responsibility. The post explained that behavioral patterns are used to build foundations that allow objects to communicate and give each other jobs to do. The chain of responsibility pattern makes it easier to chain objects into an order set and when a logical requirement or command is sent through the chain, it checks through the chain until an object is found that fulfills this requirement or command. It then goes on to explain some real-life applications for this design pattern like government and business systems where there is high value in order of commands. The post also clarifies that in the chain of responsibility the order moves upward rather than downwards which means that it starts at the bottom of the list and moves up. There is code shown afterwards that shows how the pattern works in a programming setting using book titles as an example. Using book titles, authors, and cover types, a chain of responsibility is created and tested by calling those objects based off one of those specific properties.

      This post really interested me because it was noted as a foundational design pattern which made it seem important to learn. The examples were helpful in this post as they allowed an easier understanding of the material using real code. The analogies that were used could be a bit better but overall, they weren’t too hard to grasp. The real-life applications that were shown were interesting but in my opinion there could have been more explanation as to what specifically this pattern could accomplish within business and government. The blog helped me solidify the idea that the chain of responsibility is created with objects and goes through each object to find the specific requirement needed. I did not know that the chain started from the bottom and went upwards which is good to know but I would like to know more about the efficiency of the order in the chain. More specifically, is there a way to efficiently order the objects in the chain to make it run faster? Does the order matter within the chain enough to influence efficiency? These were some questions that I still had after reading this post, but it was a good source of information to help me get an introduction to the design pattern. This material affected me by showing be a new way to code using a foundational design pattern. This will affect my future coding practices as I can now identify situations where I can apply this pattern to make it easier to organize and run better.

From the blog CS@Worcester – Student To Scholar by kumarcomputerscience and used with permission of the author. All other rights reserved by the author.

Java Testing Tips

Since I would consider myself a novice with Junit and java testing, I decided to take it upon myself to try a learn a bit more about it since we have been using it in class. I found a blog on ZeroTurnAround.com by David Salter that discusses a few tips on this topic, which I found to be quite insightful, so I am hoping to relay those tips to you.

The first tip is to follow the AAA pattern when writing tests. That is Arrange, Act, Assert. Arrange the conditions at the start of the method, act on the system, and then assert that the results are what you expected them to be. I am always a fan of easy ways to remember things, so I really like this acronym. It a nice easy way to remember what a good java code test should include.

To go along with the AAA, there is an important thing to remember when using the last of the A’s, assert. Although assert is a cool and powerful feature, you must be careful as to where and how often you use them. One should be careful that they are not testing things that the method wasn’t intended to test. It is also important to make sure you are not testing too many things in one method. This cause headaches if a tests fails, because it requires debugging multiple methods/classes, rather than being able to focus on just one. This tip really stood out to me because I think one can easily go down this rabbit hole thinking that they are making their lives easier, while in reality they are making it harder.

The last item I want to discuss is important to testing, but it is also important with regular development as well. Take advantage of what the software has to offer you. It can make your life a lot easier in the long run if you take the time to learn a new feature or two. Although you have to invest time upfront learning how it works, you can save a lot of time because that feature makes it easier for you to develop, debug, etc. For example, libraries like EasyMock and JMockit allow you use a mock object. This allows you to “mock” objects that do not exist yet. The example used in the blog us mocking a security system that controls who can access what, depending on the user logged in. Because you are able to create a mock one, you are still able to test your product, even though a key component is missing.

Obviously there a lot of different tips a whatnot to help make us better testers. This really is just the tip of the iceberg, but I hope it was as useful to you as it was to me.

Link:

https://zeroturnaround.com/rebellabs/top-testing-tips-for-discriminating-java-developers/

 

From the blog CS@Worcester – README by Matthew Foley and used with permission of the author. All other rights reserved by the author.

Some Traits of Smelly Designs

In the past, I have talked about Code Smells. However, did you know there is also a Design Smells theory? What’s the difference? Well, according to the CodeOps blog, “Design smells are certain structures in the design that indicate violation of fundamental design principles and negatively impact design quality.”. In other words, the difference between code and design smells is Design Smells focus on the design quality and principals (the architecture of the code) while Code Smells focuses on poor coding practices (what bring the architecture to life). The blog mentions a couple of red flags to look out for the may be an indication of Design Smells that I feel are worthy of discussing. Since I know I have perhaps accidentally or perhaps out of laziness have done some of the thing mentioned in this blog, I figure it can a good learning experience for both myself and the readers of this blog.

Violation of design principals: They use the java calendar class as an example. Not only does it support dates, but it also supports time. Since it has multiple roles, it is in clear violation of the Single Responsibly Principle (the first of the SOLID principals discussed a few weeks back). This is known as Multifaceted Abstraction smell. When you think about it, violating design principals is clearly a bad idea. The principals are there to promote better design and coding, so going directly against is clearly not the brightest idea.

Inappropriate use of design patterns: This one is on the opposite end of the spectrum. Instead of complete ignoring common practices to promote better code, you force it upon yourself. Just because the design pattern could be used in whatever situation you might be in, it doesn’t mean that it should be. Don’t feel obligated to use them if you feel if it will do more harm than good.

Language Limitations: Sometimes languages force you to do thing you don’t want to do, and often times it can be out of your control. Java is used as an example again. Because java does not support primitive types, if you need to take in different primitive types, you will need repeat the code, with the type taken in being the only difference. While I agree that language limitations can promote bad practices, I don’t know if it is fair to considered this to be a trait of a smelly design since unless you were able to pick the language, there is largely nothing that can be done about it.

Viscosity: This is basically taking the easy way out. Sometimes there is a hacky way to solve a problem that may be prone to errors, isn’t modular, etc., but it saves significant time and resources. Because developers are often under a time crunch, they often resort to this. I know I have, but I also know it will come back to bite you. Avoid the hack if possible.

Obviously, there are various other causes of smelly designs, but I hope this short list gave you a good idea of what Design Smells is all about.

Link:

http://www.codeops.tech/blog/linkedin/what-causes-design-smells/

From the blog CS@Worcester – README by Matthew Foley and used with permission of the author. All other rights reserved by the author.

Most Used Programming Languages

https://www.inc.com/larry-kim/10-most-popular-programming-languages-today.html

 

This article lists the top ten most commonly used languages for programmers in the real world industry. It also talks about each one for about a paragraph explaining its strengths and weaknesses, as well as what specific fields of programming use each. Since I am still learning programming, it makes sense to see which ones are going to be in higher demand as i seek jobs after college. Knowing more languages is like having more tools under your belt to solve a problem, and being able to put more down on your resume will set you apart from other candidates.

The programming language with the number 1 spot in the top ten list, is java. Java is mainly used for building server-side applications, video games and mobile apps. It is the most commonly used language because a lot of developers start by learning java first, since it is fairly user friendly. Java excels at being able to run on multiple platforms, as it is designed with the concept of WORA (write once, read anywhere).

The second most popular language is python. This is interesting news to me because I’m not very familiar with python, so now i might just look into it a bit further. Python is a general framework for mostly anything involving coding, you can find it anywhere and write pretty much anything using it. It is credited as the easiest programming language to learn because of its uncomplicated syntax, so if you already know a language its very easy to adapt to python.

Moving a bit further down the list, number five is JavaScript, which is entirely separate from the language of java. JavaScript is mainly used for online web applications. This language makes it very easy for developers to create interactive elements to their website and allows a lot of online customization options.

Also pertaining to web development, number six is PHP (personal home page, renamed to Hypertext Preprocessor). PHP is a very heavy duty language, used for dynamic big data websites, making it a great language to learn for any aspiring web developer. Another great feature is that PHP is a completely open source language, meaning the community has created many free modules anybody can use to perfectly fine tune their program to fit their exact needs.

The last but not least language on the list is C. C is the basic programming language that modern object oriented languages such as java and C# were built off of. The advantage to knowing C is that you have an understanding of the bare-bones of your code, being very close to how the machine reads it. C is more of an academic language, taught in colleges but not very used in the industry, although the knowledge and experience you gain from learning C you can use anywhere.

From the blog CS@Worcester – CS Mikes Way by CSmikesway and used with permission of the author. All other rights reserved by the author.

Most Used Programming Languages

https://www.inc.com/larry-kim/10-most-popular-programming-languages-today.html

 

This article lists the top ten most commonly used languages for programmers in the real world industry. It also talks about each one for about a paragraph explaining its strengths and weaknesses, as well as what specific fields of programming use each. Since I am still learning programming, it makes sense to see which ones are going to be in higher demand as i seek jobs after college. Knowing more languages is like having more tools under your belt to solve a problem, and being able to put more down on your resume will set you apart from other candidates.

The programming language with the number 1 spot in the top ten list, is java. Java is mainly used for building server-side applications, video games and mobile apps. It is the most commonly used language because a lot of developers start by learning java first, since it is fairly user friendly. Java excels at being able to run on multiple platforms, as it is designed with the concept of WORA (write once, read anywhere).

The second most popular language is python. This is interesting news to me because I’m not very familiar with python, so now i might just look into it a bit further. Python is a general framework for mostly anything involving coding, you can find it anywhere and write pretty much anything using it. It is credited as the easiest programming language to learn because of its uncomplicated syntax, so if you already know a language its very easy to adapt to python.

Moving a bit further down the list, number five is JavaScript, which is entirely separate from the language of java. JavaScript is mainly used for online web applications. This language makes it very easy for developers to create interactive elements to their website and allows a lot of online customization options.

Also pertaining to web development, number six is PHP (personal home page, renamed to Hypertext Preprocessor). PHP is a very heavy duty language, used for dynamic big data websites, making it a great language to learn for any aspiring web developer. Another great feature is that PHP is a completely open source language, meaning the community has created many free modules anybody can use to perfectly fine tune their program to fit their exact needs.

The last but not least language on the list is C. C is the basic programming language that modern object oriented languages such as java and C# were built off of. The advantage to knowing C is that you have an understanding of the bare-bones of your code, being very close to how the machine reads it. C is more of an academic language, taught in colleges but not very used in the industry, although the knowledge and experience you gain from learning C you can use anywhere.

From the blog CS@Worcester – CS Mikes Way by CSmikesway and used with permission of the author. All other rights reserved by the author.

The Software Craftsman 3 & 4 Week 9

In the first section of the reading first goes over what software caftsmanship is. It goes on to say that it is about a developer mastering his/her skill and being the best they can be while being professional and responsible. A craftsman will also look for partners to work with that are as professional as they are. It is also about having a good reputation, so projects being worked on are taken very seriously. Being a software craftsman is a lifestyle, not just a job.

The second section of the reading starts off by basically saying it is your responsibility as a professional to keep learning and keep up with current technology. It goes on to say that you own your career, no one else, so you must always be learning and practicing. Some companys may help you learn new things but it is not their responsibility and you would be lucky if they do.

From the blog CS@Worcester – Software Testing by kyleottblog and used with permission of the author. All other rights reserved by the author.