Interview Question About the Use of an Interface

Hi

Often times I get asked where you have implemented interface in your framework. I am a test Automation engineer for 2 years and I never used it. Can anyone please give an overview where you have used interface? Please. In which situations you would use interface?

Hello @dhk.sye1234 and welcome!

Great question! Understanding interfaces also provides testers an opportunity for improving application design. Interfaces help reduce dependencies which improves testability. I recommend advocating for testability in all products.

I interpret the term “interface” to mean a language construct. I think it’s important to understand where and why we might use one in the context of testing.

As a language construct, and interface defines properties and method of a class. In this manner, the class is a template from which can be constructed behaviors. A common example is an interface defines an animal and the class built on the animal interface implements a cat or a dog (see more details here; it is a Java example but C# supports interfaces too).
In my opinion, this is a powerful testing tool because it allows the automation developer to create mocks of classes. In that manner, the automation developer can provide an implementation that mocks the actual implementation and provide testers a method of exploring many scenarios. This may simplify the task of creating or finding specific test data.

Let’s say we have a banking application that evaluates loan applications. At the business level, the application collects information about the applicant. The business level submits this information to the logic level. The logic level could return one of three values indicating the maximum amount of of the loan. Based on those values from the logic level, the business level displays “Small”, “Medium”, or “Large”.
When we want to evaluate just the business level, we can use a mock of the logic level. The tester creates three tests using the mock to return each of the three values. Note the logic level would have its own set of tests.

In approaching test design in this manner, we provide the tester the ability to isolate behaviors and simplify the tests. Regardless of how the logic level is implemented, the business behavior can still be tested because we used a mock.

I have used RhinoMocks as a mocking tool; there are others.

Joe