茉莉私有方法的单元测试 [英] Private method Unit testing with Jasmine

查看:264
本文介绍了茉莉私有方法的单元测试的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是编码的测试案例使用茉莉角度的应用程序。但是,许多内部方法声明为私人服务。

I was coding test cases for an angular application using jasmine. But many internal methods are declared as private in the services.

例如:

App.service('productDisplay', function(){
    var myPrivate = function(){
        //do sth
    }
    this.doOfferCal = function(product, date){
        //call myPrivate
        //do sth too
        return offer;
    }
});

使用茉莉它可以直接为doOfferCalcode测试,但我想要写myPrivate单元测试了。

Using jasmine it straightforward to code test for "doOfferCal" but I want to write unit test for myPrivate too.

我该怎么办呢?

先谢谢了。

推荐答案

有没有你想测试你的私有方法具体的原因是什么?

Is there a specific reason you wish to test your private methods?

通过测试 doOfferCal(),你含蓄地测试一个 myPrivate()正在做正确的事情。

By testing doOfferCal(), you're implicitly testing that myPrivate() is doing the right thing.

虽然这是RailsConf上,三弟梅斯对很好的会谈应该怎样测试

Though this is for RailsConf, Sandi Metz has a very good talk on what should be tested.

这篇关于茉莉私有方法的单元测试的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆