简体   繁体   English

如何测试没有实现的接口

[英]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. 我正在为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? 如果您正在执行测试驱动的开发,请编写测试以查找期望getElectroniceSignatures返回的内容,可能是指定类型的非空列表? 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中的“测试”?)。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 我是否需要测试接口的每个实现来测试接口? - Do I need to test each implementation of an interface to test the interface? 我是否需要只有一个实现的接口? - Do I need an interface that has only one implementation? 如何将接口与通用类的实现绑定? - How do I bind the Interface with Implementation for Generic Classes? 如何创建检查实现是否满足接口的方法? - How do I create a method to check that an implementation satisfies an interface? 我如何确保通过接口实现公共静态功能 - How do i ensure implementation of a public static function with interface 如何在具有扩展另一个接口的接口的实现上设置限定符 - How to set Qualifier on an Implementation that has an interface which extends another interface 我如何在比较接口的两种实现类型的通用接口中声明 static equals 方法? - How do i declare a static equals method in a generic interface that compares two types of implementation of the interface? 如何使用以Object作为参数的方法正确实现接口? - How do I correctly implement an interface with a method that has Object as an argument? 我如何知道我是否在Eclipse中查看Java接口或实现文件 - How do I know if I'm looking at Java interface or implementation file in Eclipse 如果实现不可用,如何实例化接口? - How can I instantiate an interface if implementation is not available?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM