Search icon
Subscription
0
Cart icon
Close icon
You have no products in your basket yet
Arrow left icon
All Products
Best Sellers
New Releases
Books
Videos
Audiobooks
Learning Hub
Newsletters
Free Learning
Arrow right icon
Mastering Unit Testing Using Mockito and JUnit

You're reading from  Mastering Unit Testing Using Mockito and JUnit

Product type Book
Published in Jul 2014
Publisher
ISBN-13 9781783982509
Pages 314 pages
Edition 1st Edition
Languages
Author (1):
Sujoy Acharya Sujoy Acharya
Profile icon Sujoy Acharya

Working with test smells


Code smell is a technical debt or symptom that indicates a deeper problem. Smells are not bugs, or they don't fail tests. Instead, they indicate a problem in design or code such that a rigid code cannot be enhanced or can create a maintenance issue. This section covers the test smells that should be refactored for maintenance and readability. The following topics are covered:

  • Test code duplication

  • Conditions in test code

  • Test logic in the production code

  • Over engineering

Refactoring duplicates

Code duplication is the simplest code smell. It creates maintainability problems. The same code is written in many places; if any bug is found, then you need to modify all other places. This subsection elaborates on the duplicate code in test cases.

Suppose you are designing a hospital management system and writing a test for checking a patient in. The following objects are needed for the patient check-in process: a person, a guarantor, reason for hospitalization, the attending physician...

lock icon The rest of the chapter is locked
Register for a free Packt account to unlock a world of extra content!
A free Packt account unlocks extra newsletters, articles, discounted offers, and much more. Start advancing your knowledge today.
Unlock this book and the full library FREE for 7 days
Get unlimited access to 7000+ expert-authored eBooks and videos courses covering every tech area you can think of
Renews at $15.99/month. Cancel anytime}