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
Refcards Trend Reports Events Over 2 million developers have joined DZone. Join Today! Thanks for visiting DZone today,
Edit Profile Manage Email Subscriptions Moderation Admin Console How to Post to DZone Article Submission Guidelines
View Profile
Sign Out
Refcards
Trend Reports
Events
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
Partner Zones AWS Cloud
by AWS Developer Relations
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
Partner Zones
AWS Cloud
by AWS Developer Relations
Building Scalable Real-Time Apps with AstraDB and Vaadin
Register Now

Trending

  • Authorization: Get It Done Right, Get It Done Early
  • Scaling Site Reliability Engineering (SRE) Teams the Right Way
  • Replacing Apache Hive, Elasticsearch, and PostgreSQL With Apache Doris
  • Never Use Credentials in a CI/CD Pipeline Again

Trending

  • Authorization: Get It Done Right, Get It Done Early
  • Scaling Site Reliability Engineering (SRE) Teams the Right Way
  • Replacing Apache Hive, Elasticsearch, and PostgreSQL With Apache Doris
  • Never Use Credentials in a CI/CD Pipeline Again
  1. DZone
  2. Data Engineering
  3. Databases
  4. Should I Test at the GUI Level or the API Level?

Should I Test at the GUI Level or the API Level?

Where do you test? Can you isolate functionality? If so, test the isolation most heavily. Then look to see what integrates, and how it integrates.

Alan Richardson user avatar by
Alan Richardson
·
Feb. 16, 17 · Opinion
Like (8)
Save
Tweet
Share
10.32K Views

Join the DZone community and get the full member experience.

Join For Free

question: is there a rule of thumb when deciding to test at the gui level or api level? are any rules to help decide when to test at one level over the other?

answer: i don’t think i use a simple rule of thumb — but i will try and explore some of the thought processes i use to make the decision.

when i am trying to decide whether to test at the gui or the api level, i have to figure out:

  • what am i trying to test?
  • can i isolate the functionality i’m testing to a specific level?

i think the word "isolate" might be the "rule of thumb" you are looking for.

  • test heavily where you can isolate.

  • test the integration heavily for the isolated unique integration functionality.

  • test the integration as heavily as the implementation requires.

  • test the integration for emergent behavior.

  • test the overlap between systems, during integration, more lightly.

for example, if the system has "create user" functionality:

  • exposed through the gui via an admin interface.
  • exposed via an api rest call.

i need to test at both levels because the functionality of ‘create user’ is not isolated to one level.

the questions i have to ask though are ‘how much’ and ‘what’ do i have to test at each level? i may decide not to test as much through the gui if my gui calls the rest api because i can model that as (at least) two communicating systems. a gui system and an api system.

i can heavily test the parts of functionality that are isolated in the api at theapi level, and then lightly test the overlap of the integration between the gui and the api. and i want to test the unique functionality in the gui. e.g. the gui may have ajax calls triggered from gui interaction — i want to test that at the gui level.

depending on the development process we may find that the ‘ajax’ calls have already been covered by javascript unit tests. but they haven’t been integrated into the browser page, or from all the browsers and operating systems the gui is used in. therefore, depending on the libraries used, i may want to test that cross browser and on different operating systems.

if the gui calls a different backend endpoint than the api, then i need to test both routes through to the backend code until i get to the point in the backend system where i encounter shared code — assuming there is shared code in the system used by both the rest api and the gui triggered backend flow.

but at this point, i also need to consider how much coverage we have from unit tests which cover the shared code.

i guess my rule of thumb might look like a list:

  • build a model of the system such that you can identify the integration points and the ‘isolated’ shared functionality.
  • test isolated functionality at the lowest points you can.
  • work back out to higher (or peer) levels of integration and abstraction and consider the system in terms of integrating systems.
  • look for unique functionality at the higher (or peer) levels of abstraction, you will need to test them there.
  • if you exercise unique functionality in isolation by mocking out the integrating systems, then you might need to look at this from a technical risk perspective and decide if, or how much, you need to exercise it while integrated.

i could also model the above as:

  • create multiple overlapping models of the system.
  • consider coverage of the multiple models of the system.
  • consider coverage of flows through the different models of the system.
  • consideration of technical risk relating to the implementation and the environments the system runs on.

p.s. when i explain this, people often map this on to their favorite pyramid model. i don’t use any pyramid models. i prefer to model the system that i’m working with, rather than have a general model. other people prefer pyramid models.

unit test API

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

Opinions expressed by DZone contributors are their own.

Trending

  • Authorization: Get It Done Right, Get It Done Early
  • Scaling Site Reliability Engineering (SRE) Teams the Right Way
  • Replacing Apache Hive, Elasticsearch, and PostgreSQL With Apache Doris
  • Never Use Credentials in a CI/CD Pipeline Again

Comments

Partner Resources

X

ABOUT US

  • About DZone
  • Send feedback
  • Careers
  • Sitemap

ADVERTISE

  • Advertise with DZone

CONTRIBUTE ON DZONE

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

LEGAL

  • Terms of Service
  • Privacy Policy

CONTACT US

  • 600 Park Offices Drive
  • Suite 300
  • Durham, NC 27709
  • support@dzone.com

Let's be friends: