Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6224231
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T08:38:09+00:00 2026-05-24T08:38:09+00:00

How can I enforce that my test class covers a particular interface? Also is

  • 0

How can I enforce that my test class covers a particular interface?

Also is there a convention for writing overloaded test methods, so the names are consistent (my current technique is something like: methodName + parameter1Type + parameter2Type + …)?

I’m hoping the second question will be covered/avoided if there is a good way to do the first.


My issue is I have classes which implement a number of interfaces. Since I’m testing Spring injected service classes, everything has at least one interface.

Anyways say I have a class that implements:

public interface MyInterface{
    int doFoo(int input);
    int doBar(int input);
}

Lets say MyInterfaceImpl, implements this interface.

Now my test class will look something like:

import static org.junit.Assert.assertEquals;
import org.junit.Test;
public class MyInterfaceImplTest{
    private MyInterface = new MyInterfaceImpl(); //could inject it...

    @Test
    public void doFooTest(){
       //content of test not relevant
    }

    @Test
    public void doBarTest(){
       //content of test not relevant
    }
}

Now the above isn’t to bad in terms of size, but it’s hard to know if I’ve covered all the testing in larger classes, I could have missed one. Also I find it anyoying to create method names for overloaded methods. I could also add functionality to a class and possibly missed it. If I’m doing TDD this would be nearly impossible but I’d still like to be sure. What I’ve been tempted to write is…

public class MyInterfaceImplTest implements MyInterface{

And then I’d like to stick @Test in front of each method. Of course this isn’t going to work because, well the test needs to put the values in. But using implements lets the IDE add the methods and it enforces that the full interface has been implemented. To be clear I know I am not looking to actually implement the interface in the test, but I think it could speed up development if I could do something like this.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-24T08:38:09+00:00Added an answer on May 24, 2026 at 8:38 am

    To me this depends on what you mean by “enforce” and “covers a particular interface”.

    If your interface methods imply certain “contracts” (e.g. java.util.Collection.add() returns true if the receiving collection was modified as the result of the call), that you want to ensure are upheld by implementers of the interface, you can create a Contract Test.

    If you want to see that all methods of a test subject are exercised by a particular test class, you can run the test under a code coverage tool like EMMA or Cobertura and ensure the results are to your liking.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

How can I automate a test to enforce that a body of Python 2.x
I'm looking for a script/tool that can be customized to check and enforce coding/naming
How can I enforce that all Car s should have Tyre s of a
Is there a way to enforce that a type parameter passed to an attribute
In Scala I can enforce type equality at compile time. For example: case class
I'm trying to make a basic Address class, that many different other classes can
How can I enforce the JFileChooser filetype (when saving). I have implemented a file
Simple question. Just wondering if this can be done without me having to enforce
Can somebody point me to a resource that explains how to go about having
Can a LINQ enabled app run on a machine that only has the .NET

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.