Category Archives: Week-15

Understanding JUnit: A Guide to Automated Testing in Java

What is JUnit?

JUnit is an open-source framework used for automated unit testing in Java. Unit testing involves testing small, isolated units of code to verify that they function as expected. These units could be individual methods, classes, or even a line of code.

When developers write code, they also write tests for that code using JUnit. These tests are then run automatically, checking for any deviations from expected behavior. JUnit provides feedback in the form of pass or fail results.

Why Unit Testing with JUnit?

Unit testing, facilitated by JUnit, offers several benefits:

  1. Early Bug Detection: By writing tests before or alongside the code, developers catch bugs early in the development process. This ensures that issues are addressed promptly and doesn’t propagate further.
  2. Code Reliability: Writing tests encourages writing modular, well-structured code. This leads to more reliable and maintainable codebases.
  3. Confidence in Changes: With a comprehensive test suite, developers can refactor or modify code confidently, knowing that any breaking changes will be immediately flagged by failing tests.

Features of JUnit

JUnit offers several features that make it popular among developers:

  1. Open Source: Being open source, JUnit is freely available for developers to use and contribute to. This fosters a vibrant community and ensures continuous improvement.
  2. Annotations: JUnit provides annotations to identify test methods, setup, teardown, and more. These annotations make test code more readable and maintainable.
  3. Assertions: It includes a set of assertion methods to validate expected outcomes. These assertions help in comparing actual results with expected results.
  4. Test Runners: JUnit has test runners that execute tests and report the results. It supports different types of test runners for various testing scenarios.
  5. Automated Test Running: Tests run automatically without manual intervention. This saves time and effort and provides quick feedback on the code’s health.

JUnit Annotations

Annotations in JUnit provide metadata to methods to control their behavior during testing:

  • @Test: Marks a method as a test method.
  • @Before: Executes before each test method.
  • @After: Executes after each test method.
  • @BeforeClass: Executes once before any test method in the class.
  • @AfterClass: Executes once after all test methods in the class.

Conclusion

JUnit is a vital tool for Java developers, ensuring code quality, reliability, and maintainability. Its features, including annotations and automated testing, make it invaluable in modern software development.

By understanding JUnit and incorporating it into your workflow, you can write better, more robust Java code. Embrace automated testing with JUnit, and watch your code quality soar!

Source: https://www.simplilearn.com/tutorials/java-tutorial/what-is-junit

From the blog CS@Worcester – CS: Start to Finish by mrjfatal and used with permission of the author. All other rights reserved by the author.

Pattern: Expose Your Ignorance

Summary: “Expose Your Ignorance” advocates for honesty and humility in software development by encouraging developers to openly admit what they don’t know and actively seek learning opportunities. The pattern emphasizes that expertise is a result of the learning journey, not the end goal, and that building trust within teams is essential for growth.

Reflection: I really resonate with the idea of embracing ignorance as a natural part of learning, especially in an industry where it feels like you need to know everything. Admitting what we don’t know can be tough, but I’ve learned that it actually creates a better environment for learning.

Embracing Vulnerability: Admitting that we don’t know something can make us feel vulnerable, but it’s also a powerful way to build trust within our teams. Being humble and honest about our knowledge gaps encourages others to do the same. It creates an atmosphere where asking questions and seeking help are seen as strengths rather than weaknesses.

Shift in Mindset: It’s a real game-changer to shift our mindset away from always needing to appear competent. Instead, focusing on showing our ability to learn and adapt makes us more resilient. It takes away the fear of failing and makes us more willing to take on challenges. Plus, it encourages us to keep improving, which is crucial in such a fast-paced field.

Craftsmanship Analogy: Comparing software development to craftsmanship really speaks to me. Like a craftsman honing their skills, we need to keep expanding our knowledge base. It’s not about being an expert right away, but about constantly growing and learning. Expertise comes with time and practice.

Personal Experience: I’ve seen firsthand how embracing ignorance has helped me grow both personally and professionally. Being open about what I don’t know and actively seeking to learn has boosted my confidence and strengthened my relationships at work. Asking questions and being open to feedback have been key in my development as a developer.

Conclusion: “Expose Your Ignorance” is a great reminder that it’s okay not to have all the answers. By embracing our ignorance and actively seeking knowledge, we create opportunities for growth and improvement. It’s a lesson I’ll definitely keep in mind as I continue on my career path.

From the blog CS@Worcester – CS: Start to Finish by mrjfatal and used with permission of the author. All other rights reserved by the author.

Object-Oriented Testing

Object-oriented testing is about ensuring that the object-oriented software works as it should. Testing is important in any project so it’s important to make sure that the code isn’t buggy or crashes. Object-oriented testing has specific techniques that test our object-oriented program by focusing on what matters the most like unit, subsystem, and system testing. Unit testing breaks down each class and test, it helps catch errors and figure out if things are talking to each other as they should be. Subsystem testing is like testing a group of classes together, it shows how they work as a team and how it handles anything outside of it. System testing makes sure to test everything in the system and check if everything works together, leaving a top-notch system. When it comes to object-oriented testing it’s important to look out for bugs, test everything, and clean code sooner rather than later. Testing is about finding any bugs and errors that can be fixed, so looking for those bugs would help solve any problems the software has.  Instead of cleaning up the code after it’s completed, it’s useful to test it early and keep at it so that the issues are fixed sooner rather than later.

I felt like object-oriented testing has given me more information about testing and even though I know that there are different types of testing it’s given me a better idea of how they work. This reading is important for software developers who would rush through their work and not practice clean code because it emphasizes testing earlier to find any errors and clean up code that could make it confusing for other software developers. The reason why I chose this topic is because object-oriented testing is important in software development and without this information, it can cause a lot of problems and more work for developers to do when it’s avoidable and fixable. Object-oriented testing plays a huge role in software development making it important to know how it works and what is easy to detect. It also teaches software developers more about clean code and makes sure that the code is readable and understandable for other developers.

https://goodpractices.home.blog/2019/11/27/object-oriented-testing/

From the blog CS@Worcester – Kaylene Noel's Blog by Kaylene Noel and used with permission of the author. All other rights reserved by the author.

Software Testing Synergy: Leveraging IT Expertise for Optimization

Hey Everyone! As a student in a software testing course, the article “How Integrating IT Support Enhances Software Testing Outcomes” provided insightful perspectives that directly relate to our classroom lessons on implementing robust and comprehensive testing strategies. Having a good software testing process is important for defining quality and catching defects early before product release.
The article summarizes the key advantages of integrating IT support resources into the software testing lifecycle. It highlights how IT support teams have deep technical knowledge using testing frameworks, systems, networks, and more. By collaborating with developers and testers, they can apply this expertise to help assist processes like building robust testing environments, troubleshooting issues, identifying potential risks and creating test cases that accurately relay real-world scenarios.
I selected this particular resource because it reinforced topics we’ve covered in class about the importance of having well-designed testing processes and environments in place. The article’s examples resonated with me after completing last summer’s IT internship, where I saw firsthand how vital the support staff’s skills were for efficient testing and issue resolution when glitches started. Their ability to quickly diagnose and mediate problems minimized delays and facilitated a smooth development pipeline.
One of the most insightful sections outlined the advantages of integrating IT support beyond just bug detection. As we’ve discussed in our course lectures and materials, catching and fixing bugs is only one side of a comprehensive testing strategy aimed at delivering a high-quality product. The article demonstrated how collaborative IT-tester efforts enable a proactive, physical and mental approach for continuously validating software across the entire system and architecture. With their system-level expertise, IT staff can provide invaluable insights on creating more robust test cases that account for the complexities of production environments and real-world usage scenarios we may not anticipate.
What truly resonated was the need to tailor software testing processes and IT support services based on regional factors like the local talent pool, regulatory environment, and domain-specific challenges. This localized approach was obvious during my internship with Isto Biologics, as their IT support services catered their recommendations based on the market’s unique needs.
As I prepare for my future career, I now better appreciate the varied collaboration required for achieving comprehensive software testing and quality assurance. I expect to apply these learnings by prioritizing open communication between all stakeholders and advocating for strategic IT support integration from the onset of projects. Leveraging this relationship will be key to implementing robust testing processes that continuously validate quality while optimizing resources.

andicuni
April 28, 2024
https://www.softwaretestingmagazine.com/knowledge/how-integrating-it-support-enhances-software-testing-outcomes/

From the blog CS@Worcester – A Day in the Life as a CS Blogger by andicuni and used with permission of the author. All other rights reserved by the author.

Automated Python Testing

Going into my future projects, especially those for my summer fellowship, I have taken a distinct interest in Python. Throughout this course I have learned a great deal of how to test for object oriented compiler languages, using Java as our learning tool. I have wondered how testing might differ across different languages. And with a large project in Python coming up, I’d like to prioritize doing this the right way. I would like to practice in python testing to prepare. Luckily, recently posted last week, there was an article on the home page of Stickyminds surrounding python testing. The article’s title is Ensuring Reliable Cloud Applications: A Guide to Testing State Machines with Python by Konstantin Sakhchinskiy

Testing state machines in cloud applications involves heavy use of APIs. Python scripting is effective to help to ensure reliability, performance, and resilience. This is one way that an efficient library-heavy scripting language like Python would be useful for cloud applications. It is very effective at being implemented for many applications now utilizing the language itself, if only as an effective testing language. In the case of a cloud app for example, managing external browser profiles for automation and web scraping, users interact via API to execute their needed functions. Python can be used to expedite this process, as a way to manage state machines necessary to operate this cloud app. General approaches to testing on these state machines include separating output generation from state transition logic, focusing on individual states and transitions, testing each possible state transition, exploring boundary conditions, testing resilience to invalid input or disruptions, and checking system interaction within the broader context. The article also mentions some key tactics for mastering state machine testing, including testing for race conditions, assessing external disruptions and network challenges, handling heavy loads, and understanding technical details such as hidden states. Python scripting can automate testing processes. Using asyncio and httpx, scripts can simulate user interactions with the cloud service, testing responsiveness. Tailoring tests to specific needs and monitoring system performance using tools like Grafana and Kibana are essentia, and made more efficient with Python’s wide variety of usable systems. Overall, testing state machines is crucial for ensuring application reliability, and Python scripting offers effective ways to automate and simulate real-world scenarios for comprehensive testing.

My view on testing applications was expanded greatly by this article. The prevalence of automated testing libraries throughout other languages to enforce scripting was a surprise to me. And this article has helped me to understand the real role of specific and intentional testing of software. I was also surprised to find that state machines were very important to understanding how to test and break down code, as this is something I learned a lot about in the fall. I am not working with external applications or languages outside of Python for this project, so I will not utilize these libraries to automate my testing, but going forward this knowledge is imperative.

Source:

https://www.stickyminds.com/article/ensuring-reliable-cloud-applications-guide-testing-state-machines-python

From the blog CS@Worcester – WSU CS Blog: Ben Gelineau by Ben Gelineau and used with permission of the author. All other rights reserved by the author.

Blog #6: Performance Testing

Performance Testing is a subject I just recently discovered is included in the Software Quality Testing umbrella term. Outside of casually monitoring CPU and GPU usage while using demanding software, I have little knowledge of what Performance Testing is. As a future worker in the Computer Science field, knowing how to report and minimize hardware stress must be an invaluable skill.

During my search to understand what Performance Testing is, I found an article written by Tricentis that included an in-depth explanation for each step (or deviation) of Performance Testing. Before going into detail, Tricentis highlights that performance testing is a direct solution to ensuring the stability and scalability of software. If performance testing is ignored, then users may encounter issues with speed, crashes, or data loss within their application. Testing seems to flawlessly integrate with CI/CD models, as testing should occur whenever a working model is available. This allows the development team to fix issues early before they sink too deep into the product’s foundation. Within the realm of performance testing, some subtests aim to find results for specific metrics. A few that I was unfamiliar with are as follows. Regression tests seek to test two states of the program, one being the current model, and the other being one with experimental changes. Both of these models work together to compare the hardware performance. These are used to highlight whether changes from the most recent version are more damaging to the product. Functional tests focus more on the software aspect of the product. Using this test will yield results on whether the UI elements, APIs, etc are all functioning correctly. Lastly, load testing seeks to put the product under great stress by simulating several concurrent users. Testing with this will give the developers insight as to how their product will function once published to the general public. Metris from load testing will help reinforce the product before it can fail after its initial release.

Performance testing will yield several useful metrics to guide the development of the product. These metrics include hardware bottlenecks, response time, and load time. Issues about these metrics must be addressed during the development process as they directly impact the reliability of their product post-release. Untested hardware is an active detriment to the developers, and will further damage the development process. Following the idea of testing software ‘frequently and consistently’, developers must also view how the current state of their product affects the hardware it will operate on.

-AG

Source: https://www.tricentis.com/learn/performance-testing

From the blog CS@Worcester – Computer Science Progression by ageorge4756 and used with permission of the author. All other rights reserved by the author.

Week 15

Last week my group and I were discussing behavior-driven development. It is a type of development that refines our previously learned developments. This is a great jumping point to what we were previously learning and it will make for a great assignment. I would like to give more information on this subject matter because it is valuable. This is another practice that is used in the field that can be used in the future.

Behavior Driven Development (BDD) is an agile testing practice that prioritizes creating automated tests first before specifying system behavior. BDD is utilized in a group setting where both agile teams and business participants can see eye to eye. BDD are tests used to capture a story, feature, or capability from a user’s perspective. During this development, there should be three different heads of mentality to considered. Customer minds usually stakeholders understand the business needs and their desire for new requirements. Developers understand what needs to be done to accomplish their responsibilities and technological feasibility. Test-centric minds should consider any exceptions, new edges, and boundary conditions. There are three phases during BDD discovery, formulation, and automation. The product owner or product manager creates criteria that must be used to write a good story. Then, the discovery process where the team finds any additional information that could enhance the criteria. There is an automation phase that automates the acceptance test. This test shares a lot of similarities with Acceptance Test–Driven Development (ATDD) and Specification by Example (SBE). 

This new development strategy was very useful to learn. It’s good to understand different types of development plans and how you can combine them to make a stronger development cycle. During the agile team cycle, I feel like every cycle you can change what type of software development you use for that cycle. Based on the project, resources, and time you can choose different software developments. Learning about BDD gave me an insight into the business side of the development process. These are things you may not think about when creating your software but should be a priority. You would expect your software project to be examined by someone who is informed in the field but to try to explain to someone that is funding it would be a hassle but necessary. It makes sense that people who aren’t on the team would have to understand the development. It’s a group effort between multiple teams that all must work in unison to create a working product.  

https://scaledagileframework.com/behavior-driven-development/

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

Blog #5: Testing with Jest

JavaScript is a programming language completely foreign to me. At one point in the near future, I see myself learning the basics just to gain general exposure to it. It differs enough from my first object-oriented language, that being Java, to the point where it seems valuable to have some experience in it. With this in mind, I began my search to see what testing framework would work for this language and how tests are conducted differently.

In my search, I discovered this testing framework named Jest. This is a testing framework that is most known for testing Javascript but has also seen usage with other languages such as Angular and React. According to the author of the blog post The Pros and Cons of Different Test Tools – Jest, Craig Risi, he immediately states this testing framework is much more user-friendly than others. Jest does not require the users to install packages or other external dependencies, as the framework has them already included. Furthermore, the included dependencies are often built on frameworks of other languages, such as Mocha or Chai, which makes Jest an incredibly flexible testing framework. An important inclusion Risi made to his blog post was the inclusion of all features Jest offers out of the box. These range from topics I’m knowledgeable of, such as Mocking and Unit Testing, and some that I’m new to, such as Snapshot Testing and Asynchronous Testing.

Towards the end of Risi’s blog post, he mentions the direct pros and cons of using Jest. As previously mentioned the versatility between languages, easy start-up, and abundant features are a testament to its practicality. Unfortunately, no testing framework is flawless. Several of these issues originate from the sheer size of Jest. Downloading this framework and testing smaller projects offer an issue of scalability. There are countless smaller frameworks, in terms of digital size and complexity, that are better suited for testing software. Additionally, all the features Jest includes come with their own learning curve. Users may never utilize some features as the scope of their testing does not call for Jest’s extensive collection. With both the pros and cons in mind, Jest is incredible in what it can achieve but development teams must consider the scale of their project to determine whether using it is appropriate. Reflecting on my experience with testing frameworks, I can understand the value of having that much utility from one framework, yet I don’t see myself creating a project ‘so big’ that would call for it’s entire library of features.

-AG

Source: https://www.linkedin.com/pulse/pros-cons-different-test-tools-jest-craig-risi

From the blog CS@Worcester – Computer Science Progression by ageorge4756 and used with permission of the author. All other rights reserved by the author.

Behavior-Driven Development

In last week’s class, we were tasked with creating an activity related to our course material. Our group decided on behavior-driven development (BDD) since it is related to test-driven development, which we discussed in class. BDD’s approach is user-focused and prioritizes understanding between the development team and users, but it has yet to be discussed in class. Since the post was well-organized and informative, focusing on aspects that could help developers improve their code, I decided to talk about BDD for my blog post this week. 

The blog post “Behavior-driven development principles and practices,” by Philip Rogers outlines the basics of BDD, detailing its history, principles, and practices. Phillip explains that BDD is centered around three principles: what the software could do, what the software should do, and what the software does.

  1. What the Software Could Do: This principle involves understanding what the customer wants from the software. They use discovery workshops to outline what the developers should prioritize and resolve any confusion between the users behaviors and the team.
  2. What the Software Should Do: This principle focuses on creating documentation in a human and computer readable format. This includes the given-when-then format that describes the user’s behaviors and how the software should respond. 
  3. What the Software Does: This principle focuses on using the documentation or scenarios to create automated tests and improving the code until it aligns with the customer’s requirements and the team’s goals.

The blog post also discusses Gherkin, a language used in BDD to bridge the gap between human and computer understanding. The syntax used in Gherkin helps capture user scenarios and articulate how the automated tests should work to align with those scenarios. Philip also explains the benefits of BDD, such as improved collaboration and reduced rework, and the cons, including high level of business engagement and the lack of compatibility with traditional software development. 

After reading this blog post, I better understood the BDD process and why these principles are in place. It highlighted why there would be a need to deviate from or expand test-driven development. There should be a focus on how users interact with the system using communicative language to reduce the creation of faulty features.  

In the future, I plan on being mindful of the user’s experience and creating software with my team to meet the users and, in turn, the team’s expectations. I will also look into a Gherkin and try to understand the syntax better to produce better tests and end products. 

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

Beginning JavaScript Testing with Mocha

Link to blog: https://medium.com/swlh/intro-to-javascript-testing-with-mocha-1366dad9b973

For the next (and last) couple weeks of class, we are required to create our own in-class activity as if other students were going to use it. We were tasked with choosing something different than we have done already, so my group decided on testing JavaScript programs with the Mocha framework. I personally have no experience with Mocha, but I do have a tiny bit of experience with JavaScript, so I was interested to learn more about how different testing looked compared to what I was currently experiencing. This is how I found Valerie Foster’s blog post Into to JavaScript Testing with Mocha. Here’s what I found. 

Foster does give a few instructions on how to install the Mocha framework to your project, but I’ll mainly focus on the pros and cons of testing within the framework. They include a codeblock of a simple test, however it was not 100% clear to me at first what each line meant. Here are a few things included in the codeblock, and what they do:

  • describe(string, function)
    • According to Codeacademy.com, the describe function groups tests together and uses the first parameter, the string, to explain that group. The second parameter, the function, is a callback function which has ‘it’ tests (I’ll get to that in a moment)
  • it(string, function)
    • The it function is similar to the describe function, as its parameters are the same. However, the string it accepts is instead used to explain what the test itself is checking for. So, for example it(‘should //do something when //condition’, function(){})

Foster then discusses some customization options for Mocha, but then specifies their favorite assertion library in Mocha, called chai. One of the key benefits of this library is that it might make the test functions easier to read (e.g., going from assert.equal(a, b) to expect(a).to.equal(b), according to Foster). 

I selected this article because I wanted to have more of a background on Mocha and testing with Javascript since it is going to be our project. Also, Foster seems capable and comfortable with Mocha and JS, and makes it easy to understand what is going on in tests with a framework I’ve never seen before. A good beginner’s guide is always helpful to a fresh start.

I liked this blog because it felt informative and informal; like I was being taught something new but not in a super serious tone (Foster shared their favorite terminal customization was a Nyan Cat reporter). I learned a bit more about how testing is done in JavaScript, including describe and it functions. This affected me by boosting my confidence in my ability to assist my group with our assignment and it encouraged me to learn more JS and Mocha as a whole. I expect to apply such learned knowledge to future web applications and perhaps even past projects.

From the blog CS@Worcester – Josh's Coding Journey by joshuafife and used with permission of the author. All other rights reserved by the author.