我使用的是ORM,获取记录对象的方法是使用FooModel::find(1)。FooModel有一个我需要模拟以进行测试的方法。我该怎么做呢?(不能使用PHPUnit mock,因为这样会得到一个与ID为1的记录不对应的模拟FooModel。)
编辑
示例:
class FooModel
{
// ORM model that fetches record from the DB
public function thisNeedsToBeMocked()
{
// some code here that depends on external fact
我们正在应用程序中实现“同步到日历”功能。我们的同步过程涉及从服务器端获取的事件,我们希望将这些事件复制到iPhone日历中。目前,我不确定我们为这个同步编写的方法是否解决了所有可能的情况--这就是我想要对它进行单元测试的原因。它包含对EKEventStore的多次调用,正如苹果文档所述,这些调用需要首先用requestAccessToEntityType:completion:调用:
在iOS 6及更高版本上,必须在使用requestAccessToEntityType:completion: for data to return初始化事件存储后请求对实体类型的访问。
在运行单元测试
我有一个类,它将消息写入一些日志。这个类是一个实用工具,它不做任何其他事情,它在后台运行,检查一些东西并记录它们。我想知道是否有可能在单元测试中验证日志是否已经写入,而不关心它实际写的是什么。我的班级正在接受测试:
//imports...
public class MyClass {
private static Log log = LogFactory.getLog(MyClass.class);
public MyClass() {
log.info("MyClass is being created.");
}
public void do
外部混凝土类的模拟失败,出现下面提到的错误。
java.lang.AbstractMethodError: Receiver class me.spike.LibraryTest does not define or inherit an implementation of the resolved method 'abstract java.lang.Object getProperty(java.lang.String)' of interface groovy.lang.GroovyObject.
我试过添加cglibs-nodep和objenesis,但没有成功地嘲笑具
我正在尝试对我编写的一个瘦数据访问层进行单元测试。我希望我不必将DriverManager的存根注入到建立连接的类中,而且我也没有可用的模拟框架。我对照检查了我的实现,它非常相似,但是当我运行测试时,我得到一个SQLException:“没有找到适合jdbc的驱动程序:mysql://localhost:3306。”下面是存根代码:
public class DriverStub implements Driver
{
@Override
public boolean acceptsURL(String URL) throws SQLException
{
嗨,我有一段不是很好设计的代码,但是我不是这个代码的所有者,所以我不能改变它。
public interface Car{ // This is a marker interface. }
public class BigCar implements Car{
public boolean isVeryBig(){
return true;}
}
public class QuiteBigCar implements Car{
public boolean isVeryBig(boolean withHatchBack){
return true;}
}