DZone
Thanks for visiting DZone today,
Edit Profile
  • Manage Email Subscriptions
  • How to Post to DZone
  • Article Submission Guidelines
Sign Out View Profile
  • Post an Article
  • Manage My Drafts
Over 2 million developers have joined DZone.
Log In / Join
Please enter at least three characters to search
Refcards Trend Reports
Events Video Library
Refcards
Trend Reports

Events

View Events Video Library

Zones

Culture and Methodologies Agile Career Development Methodologies Team Management
Data Engineering AI/ML Big Data Data Databases IoT
Software Design and Architecture Cloud Architecture Containers Integration Microservices Performance Security
Coding Frameworks Java JavaScript Languages Tools
Testing, Deployment, and Maintenance Deployment DevOps and CI/CD Maintenance Monitoring and Observability Testing, Tools, and Frameworks
Culture and Methodologies
Agile Career Development Methodologies Team Management
Data Engineering
AI/ML Big Data Data Databases IoT
Software Design and Architecture
Cloud Architecture Containers Integration Microservices Performance Security
Coding
Frameworks Java JavaScript Languages Tools
Testing, Deployment, and Maintenance
Deployment DevOps and CI/CD Maintenance Monitoring and Observability Testing, Tools, and Frameworks

Because the DevOps movement has redefined engineering responsibilities, SREs now have to become stewards of observability strategy.

Apache Cassandra combines the benefits of major NoSQL databases to support data management needs not covered by traditional RDBMS vendors.

The software you build is only as secure as the code that powers it. Learn how malicious code creeps into your software supply chain.

Generative AI has transformed nearly every industry. How can you leverage GenAI to improve your productivity and efficiency?

Related

  • Advanced Error Handling in JavaScript
  • Working With Vision AI to Test Cloud Applications
  • Load Testing Essentials for High-Traffic Applications
  • JUnit 5 Custom TestListeners

Trending

  • Memory Leak Due to Time-Taking finalize() Method
  • How Large Tech Companies Architect Resilient Systems for Millions of Users
  • Introducing Graph Concepts in Java With Eclipse JNoSQL, Part 2: Understanding Neo4j
  • IoT and Cybersecurity: Addressing Data Privacy and Security Challenges
  1. DZone
  2. Testing, Deployment, and Maintenance
  3. Testing, Tools, and Frameworks
  4. How to Test QR Codes in Your Applications

How to Test QR Codes in Your Applications

You’ve embraced QR codes in your applications, but are you actually testing them? See how easy it can be to include this crucial step in your SDLC.

By 
John Vester user avatar
John Vester
DZone Core CORE ·
Jan. 22, 25 · Tutorial
Likes (3)
Comment
Save
Tweet
Share
26.7K Views

Join the DZone community and get the full member experience.

Join For Free

Building quality software is only possible with quality tests. Whether you write test scripts for QA engineers or build automated tests, tests help to ensure that your applications continue to function as they grow and evolve.

However, using automated testing to verify correct behavior can be challenging if your application generates visual artifacts, such as QR codes. Granted, you can write unit tests to ensure your code for generating QR codes does what it should; however, the danger is that your tests will be too tightly coupled to your application code. You’ll need to update your tests whenever you change the application.

I’ve written about Tricentis Tosca before but recently uncovered one of its newer features. Among the suite of tools in the product is the visual verification of QR codes and barcodes. Instead of writing code to decode what my app just encoded, I can just point Tosca at my app and assert what should be in the QR code, setting aside the implementation details of how the tests work. Yes, this is how QR code testing ought to work.

Let’s take a look at an example of how this testing works.

Demo Application

Before we can test QR code generation, we need to build an app that generates QR codes. Fortunately, we can use an open source QR code generator library. This repo includes examples for implementing QR code generation in several different languages, including Java, Python, TypeScript, C, and C++. I decided to go with the Rust implementation.

When I built the Rust example, it had nice output in my console, so I went with that.


I also added some code to the example to write the first QR code to an SVG file for testing later. Note that the QR code contains the string "Hello, world!" This is what we’ll test for.


Testing QR Codes With Tosca

Now that we have an app to work with, let’s look at how to test it with Tricentis Tosca. 

As a reminder, Tricentis Tosca is codeless, AI-powered testing for your applications. It offers both cloud and local agents for running application tests. In a recent release, it introduced new support for testing QR codes.

Once my Rust code generated the QR code, I put the QR code in a PDF (the easiest way to do that is to open it and print it to PDF) and then put that PDF file in a location accessible to Tosca.

I decided to use the new test builder in Tosca Cloud to build this test since I just wanted to try it out with a simple test case. This was as simple as logging into my Tosca Cloud account and starting a new test suite. Since I’d already connected the machine to Tosca Cloud and the VM is where I’ve set up my license to use Tosca, Tosca Cloud could run the test on the node as a personal agent.

To configure the test, I simply dragged the module from Tosca’s module library for "Reading a PDF QR/Barcode" and pointed it at the PDF file. For the value field, I entered what should be in the file. That's it!

Here’s how it looks in Tosca Cloud:


Tosca also has a Web QR/Barcode validator, but using it requires me to publish an app with a URL that a test agent can access.

After setting everything up, I clicked the Run button. Tosca Cloud starts an application locally, running on my test machine and linking the test case I’ve built. This allows me to skip much of the setup necessary for a more robust test suite.

The test runs, and the test case executes. Tosca provides access to the results:


To see the full output of that last step, we can click on it to see more details.


Now, we have a passing test for our application based on the value encoded in the QR code. We don’t need to build a QR code decoder ourselves. Tosca handles decoding for us! This way, we can validate that our application behaves as expected. 

Let’s verify this by modifying what the test searches for in the generated QR code.


We’ve updated the test to search for "Hello, Tosca!" instead of "Hello, world!". At this point, our updated test ought to fail. We run the test and look at the result.


The test case fails, as expected. The details in the Verify step give us helpful information:

As we can see, the QR code does not contain the string that the test is looking for. With the application currently encoding "Hello, world!" our test fails. Let’s fix our code to match our test expectations.


We run our test again.


The test passes, and the test case details confirm why.

Now, as we change our application code or test requirements, we are confident that our QR codes generate according to spec.

QR Testing for the Win!

While this demonstration is somewhat simple, it shows the convenience of having a testing tool for QR code decoding. Additionally, the tests I’ve built for this feature are completely separate from the library I’ve used to implement the encoding functionality. This means that in the future, I can swap out the library without changing the tests at all, and my tests will tell me if the library change was seamless.

Have a really great day!

QR code Test case applications Testing

Opinions expressed by DZone contributors are their own.

Related

  • Advanced Error Handling in JavaScript
  • Working With Vision AI to Test Cloud Applications
  • Load Testing Essentials for High-Traffic Applications
  • JUnit 5 Custom TestListeners

Partner Resources

×

Comments
Oops! Something Went Wrong

The likes didn't load as expected. Please refresh the page and try again.

ABOUT US

  • About DZone
  • Support and feedback
  • Community research
  • Sitemap

ADVERTISE

  • Advertise with DZone

CONTRIBUTE ON DZONE

  • Article Submission Guidelines
  • Become a Contributor
  • Core Program
  • Visit the Writers' Zone

LEGAL

  • Terms of Service
  • Privacy Policy

CONTACT US

  • 3343 Perimeter Hill Drive
  • Suite 100
  • Nashville, TN 37211
  • support@dzone.com

Let's be friends:

Likes
There are no likes...yet! 👀
Be the first to like this post!
It looks like you're not logged in.
Sign in to see who liked this post!