Software Testing in Java

Why Automate Testing?

  1. Achieves stakeholder goals
  2. Meets functional requirments
  3. Correctly handles corner cases


Testing Code
Writing Good Tests

Writing Test Code with JUnit & Java “JUnit is a Testing framework.”

This video is an introduction how to make a Junit test in eclipse.

Given the preconditions for the test, what should the code look like when the behavior happens…


Failures VS. Errors

  • Failure
  • Tried to check a behavior
  • An assertion failed
  • Suggests the code is broken
  • Error
  • At any point in the test
  • An exception was thrown
  • Suggests the test is broken

Good Tests

Why should we care about test code quality?
– Maintenance
– Readability- Coupling

Tests are code, treat them like it… Test code is the same thing as application code if you want to be able to read your code after a year.

What does a good test look like?

DRY (Don’t repeat yourself)
Every piece of knowledge must have a single, unambiguous, authoritative representation within tests.
Behavior not implementation
Try to test the behavior of the class in action, don’t trans-pass the inner class to test it… (Don’t look at private methods)
– Implementation: “Exposing private state results in brittle and hard to maintain tests”
– Behavior: You can change the implementation and the tests still passes
Well named (For ex: PersonController the test should be PersonControllerTest)
– Naming provides executable documentation
– Maintenance: What test does what?
– Readability: When we are reading our test we need to tie our test to the body of the code
for example: assertEquals(“Wrong quantity of coffee”, 1, order.size());


Gabriel Ajabahian
Software Engineer Freelance
I am a Freelance consultant, I’m passionate about creating dynamic applications. With 10+ years technical experience as well as working on major application systems for top down.

I have extensive software engineering experience, recently I focus on Scala/Java and JavaScript. On the other hand, I have experience with C# and .net framework/core. I focus on integrating applications that are built against different frameworks and can run on different platforms.

Scalability, efficiency and performance are key topics for any software, that’s why I keep track of the newest technologies, I never underestimate the power of the cloud, that’s why I do believe in using this power with “edge applications” to expand software’s and solutions to a new level.

Being a software engineer who understand the business as well as my team, looking at things from different perspectives. Being open and honest and investing in relationship makes a big difference.

Specialties: Software development, Scrum/Agile, Process and Problem management.