简体   繁体   中英

How do I test an interface that has no implementation

I have an interface and its implementation. I'm working on a plugin for JIRA. I've just decided on its design but do not have implementation as such. I'm kinda lost on how to test it when it has no methods in it. Can anyone pls help? thanks..

package com.cerner.jira.plugins.esig.servicemanager;

import java.util.List;

import com.atlassian.jira.issue.Issue;
import com.cerner.jira.plugins.esig.issuetab.*;

public interface EsignatureManager {

    public List<EsignatureTabPanelData> getElectronicSignatures(Issue paramIssue);

}

and I have a class that implements this...

package com.cerner.jira.plugins.esig.

import java.util.List;
import com.cerner.jira.plugins.esig.customfields.UnameCustomField;

import com.atlassian.jira.issue.Issue;
import com.cerner.jira.plugins.esig.issuetab.EsignatureTabPanelData;

public class EsignatureManagerImpl implements EsignatureManager {

    UnameCustomField unamecustomfield;

    @Override 
    public List<EsignatureTabPanelData> getElectronicSignatures(Issue paramIssue) {
        return null;
    }

}

An interface cannot be tested as well as if it compiles it makes all the functions that it should do. You can't test something that do nothing, that is the case of an interface.

Test the class that implements the interface. If you are doing test driven development, write the test to look for what you expect your getElectroniceSignatures to return, possibly a non-empty list of the type you specified? If you are not, then go ahead and implement the interface member in the class first, then write a test method for the classes implementation of the interface member once you have it doing what you expect.

I guess you could start it off with something like this and change your test as you know more about your methods.

@Test
public void getElectronicSignatures(){
    fail("Not implemented yet");
}

我不知道这是否是您特定(JIRA特定)用例的答案,但是:可以测试一个接口:您可以使用反射来检查该接口是否提供了特定的方法,注释等。(但是我假设您是指JIRA中的“测试”?)。

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM