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

  • Testing Asynchronous Operations in Spring With JUnit 5 and Byteman
  • Testing Asynchronous Operations in Spring With JUnit and Byteman
  • Mastering Unit Testing and Test-Driven Development in Java
  • Hints for Unit Testing With AssertJ

Trending

  • Intro to RAG: Foundations of Retrieval Augmented Generation, Part 1
  • Exploring Intercooler.js: Simplify AJAX With HTML Attributes
  • The Ultimate Guide to Code Formatting: Prettier vs ESLint vs Biome
  • Agentic AI Systems: Smarter Automation With LangChain and LangGraph
  1. DZone
  2. Testing, Deployment, and Maintenance
  3. Testing, Tools, and Frameworks
  4. Is JUnit Only for Unit Testing?

Is JUnit Only for Unit Testing?

Can JUnit be useful for other applications beyond unit testing? Yes! It can actually be used to execute code to support any kind of testing.

By 
Alan Richardson user avatar
Alan Richardson
·
Aug. 03, 16 · Opinion
Likes (9)
Comment
Save
Tweet
Share
8.9K Views

Join the DZone community and get the full member experience.

Join For Free

Question

Hi, you use JUnit in the book Java For Testers and I thought JUnit was used for "unit testing" and "unit testing" was performed by developers, not testers. Is the purpose to learn JUnit and "unit testing" or other types of testing as well? In other words, would you recommend learning "Java for Testers" to software testers who would rather not be involved in “unit testing" but rather involved in "system and UAT"?

Image title

Answer

JUnit is used for unit testing. And, it is used for other types of testing as well.

I don’t think of JUnit as a Unit Testing Tool. Instead, I view it as a way of running code marked as "runnable by JUnit." That code is marked by  @Test  annotations and is often called a Test, and those "Tests" are often used for Unit testing, but they don’t have to be.

JUnit can be used as a test runner for any kind of test: e.g. system and integration tests; tests which are interacting with a deployed application.

E.g. the WebDriver tests here all use JUnit, and they interact with an application which runs in a browser. And you can see me using JUnit here to aid my interactive exploratory and system testing of an API. The name JUnit should not lead you to think that it is only for Unit testing.

If you want to automate, from code, then you’ll need some way of executing the code. In the book, we use JUnit as Test Runner to execute code. I see a lot of examples of “how to learn Java” which use "main" methods to allow execution of the code.

main methods are a good approach if you want to compile your code into an application.

Unfortunately I’ve seen that when people learn to write Java this way, they often have multiple "main" methods in their code, without really knowing why a "main" method is used. And, they don’t learn any strategies for running bits of code in an adhoc fashion, as well as a strategic fashion.

In the book Java For Testers I wanted people to learn Test Driven Development, but not make it a thing (just a natural process), so all the execution capabilities of the code are provided by  @Test  annotations, and executed from JUnit. This allows us to:

  • Run arbitrary code without creating main methods or packaging the app
  • Use any library, not just for Unit testing, but also for Testing that integrates with deployed applications e.g. Web or API
  • Tactically create suites which we can use longer term
  • Unit test the abstraction layers and support code that we write so that we do Unit test, our System and Integration test code
  • Easily add our code into a continuous integration approach

Hopefully, as you work through the book, that will all become clearer.

If you want to automate, you will need to write code, and you’ll want to unit test that code as well, and you’ll use JUnit for that, as well as using JUnit to provide the ability to execute your code.

I rarely unit test the applications I work on as a tester, but I do unit test the code I write to automate those applications as part of my testing.

Hope that makes sense!

P.S. I think you are unlikely to strategically automate as part of a UAT process. But you might tactically automate (adhoc) data setup and configuration, and you’ll need coding skills to do that effectively.

unit test JUnit application

Published at DZone with permission of Alan Richardson, DZone MVB. See the original article here.

Opinions expressed by DZone contributors are their own.

Related

  • Testing Asynchronous Operations in Spring With JUnit 5 and Byteman
  • Testing Asynchronous Operations in Spring With JUnit and Byteman
  • Mastering Unit Testing and Test-Driven Development in Java
  • Hints for Unit Testing With AssertJ

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!