草庐IT

mock_calls

全部标签

python技术栈之单元测试中mock的使用

什么是mock?mock测试就是在测试过程中,对于某些不容易构造或者不容易获取的对象,用一个虚拟的对象来创建以便测试的测试方法。mock的作用特别是开发过程中上下游未完成的工序导致当前无法测试,需要虚拟某些特定对象以便测试。unittest是python内置的单元测试库,在做接口测试时,如果开发的接口未开发出来,我们如果想要测试接口联调,又不能干等着,这时可以使用unittest.mock模拟接口返回,进行接口测试。举个栗子示例:1、新增登录和获取个人信息两个接口,分别由A和B开发。2、A登录接口尚未开发完成,B获取个人信息接口已经开发完成。3、已知登录接口返回3种状态:登录成功,登录失败,登

PHP fatal error : Call to undefined function mssql_query()

因此,当我想向mssqlserver查询某些内容时,我一直收到此错误。已与数据库建立连接,但查询似乎失败。错误日志包含以下内容:PHPFatalerror:Calltoundefinedfunctionmssql_query()php上的代码:session_start();include_once("connect.php");if(isset($_POST['username'])){$username=$_POST['username'];$password=$_POST['password'];$sql="SELECT*FROMtestWHEREusername='".$use

php - 使用 Mock 对 Laravel 5 邮件进行单元测试

有没有办法在Laravel5中测试邮件?尝试了我在互联网上看到的唯一合法模拟示例,但它似乎只适用于Laravel4。下面的当前代码。$mock=Mockery::mock('Swift_Mailer');$this->app['mailer']->setSwiftMailer($mock);...somemorecodeshere...$mock->shouldReceive('send')->once()->andReturnUsing(function($msg){$this->assertEquals('Mysubject',$msg->getSubject());$this->

php - mb_convert_encoding 错误 : Call to undefined function mb_convert_encoding()

我目前正在编写一个PHP函数,但是在执行完整的脚本时出现错误:错误:Calltoundefinedfunctionmb_convert_encoding()我的功能:functioncleanData(&$str){if($str=='t')$str='TRUE';if($str=='f')$str='FALSE';if(preg_match("/^0/",$str)||preg_match("/^\+?\d{8,}$/",$str)||preg_match("/^\d{4}.\d{1,2}.\d{1,2}/",$str)){$str="'$str";}if(strstr($str,'

php - 相当于 PHP 的 call_user_func() 的 javascript

有没有人知道有没有?我想使用变量名调用一个函数。编辑:我在这里发布了一个关于我正在尝试做的事情的fiddle:http://jsfiddle.net/sAzPA/...js:(function($){$.fn.MyPlugin=function(){returnthis.each(function(){varsomefunction=function(arg1,arg2){alert(arg1);},someotherfunction=function(arg1,arg2){alert(arg2);},reallyimportantfunction=function(arg1,arg2

php - Gd 已安装,但 "Call to undefined function imagecreatefromjpeg()"

看起来我的主机支持gd,但我仍然遇到错误(PHP版本5.3.28)Fatalerror:Calltoundefinedfunctionimagecreatefromjpeg()这是我的phpinfo:gdGDSupportenabledGDVersionbundled(2.1.0compatible)GIFReadSupportenabledGIFCreateSupportenabledPNGSupportenabledlibPNGVersion1.2.44WBMPSupportenabledXBMSupportenabledDirectiveLocalValueMasterValue

PHP 静态工厂方法 : dynamically instantiate instance of the calling class

此PHP问题与thisquestion有关,但有点不同。我有一个名为create()的静态工厂方法,它实例化一个类实例。我希望该方法动态实例化调用它的(子)类的实例。因此,它实例化的类必须在运行时确定。但是我想这样做而不必在子类中重新定义静态工厂方法(这在我的示例中是完全有效的,因为子类没有要初始化的新数据成员)。这有可能吗?classFoo{private$name;publicstaticfunctioncreate($name){//HEREINSTEDOF:returnnewFoo($name);//IWANTSOMETHINGLIKE://returnnewget_class

php - fatal error : Uncaught Error: Call to a member function select() on null

我对php中的OOP有点陌生,我每次在模型中都会遇到这个问题,但我找不到导致这个问题的错误。我收到一条错误消息:fatalerror:未捕获错误:在我的model的getCategories函数中调用成员函数select()onnull(参见下面的代码)。$picName,"pic_desc"=>$pd,"pic_type"=>$pt];$img=parent::$db->saveTo("pictures")->setData($data)->execute();if($img){$imgId=parent::$db->lastInsertId();$data=["name"=>$n,

php - call_user_func_array 与 $controller->$method($params)?

我在我的代码中使用它:call_user_func_array(array($controller,$method),$this->params);但我发现下面的代码做了同样的事情:$controller->$method($this->params);这两个版本有什么区别吗?谢谢亚当·拉马丹 最佳答案 它们不一样。如果$method是showAction并且$this->params是array(2,'some-slug'),那么第一次调用将等同于:$controller->showAction(2,'some-slug');而第

.NET Moq mock internal类型

问题Cannotcreateproxyfortypexxxbecausetypexxxisnotaccessible.Makeitpublic,orinternalandmarkyourassemblywith[assembly:InternalsVisibleTo("DynamicProxyGenAssembly2,PublicKey=0024000004800000940000000602000000240000525341310004000001000100c547cac37abd99c8db225ef2f6c8a3602f3b3606cc9891605d02baa56104f4cfc0