如何单元测试AppEngine渠道服务? [英] How can I unit test the AppEngine Channel Service?

查看:101
本文介绍了如何单元测试AppEngine渠道服务?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已阅读AppEngine 单元测试指南,并且我得到了Java Datastore服务测试工作正常,但我对Channel服务没有任何好运。本指南没有给出任何具体的频道测试例子,而且javadoc也没有什么帮助,但是我的IDE向我展示了一些类似于单元测试本地频道服务的类;



有没有人有任何测试GAE渠道服务的经验或例子?



  import unittest $ b 


$ b from google.appengine.api导入频道
from google.appengine.ext import testbed

$ b $ class TestCase(unittest.TestCase):

def setUp(self):
self.testbed = testbed.Testbed()
self.testbed.activate()
self.testbed.init_channel_stub()

def test_send(self):
channel_stub = self.testbed.get_stub('channel')
token = channel.create_channel('ClientID1')
channel_stub.connect_channel(token)
channel.send_message('ClientID1','hello')
channel_messages = channel_stub.get_channel_messages(token)
channel_stub.clear_channel_messages(token)
self.assertEquals(['hello'] ,channel_messages)


if __name__ =='__main__':
unittest.main()

您也可以查看渠道服务存根的源代码。


I have read the AppEngine unit testing guidelines, and I got the Java Datastore service tests working, but I'm not having any luck with the Channel service. The guide doesn't give any specific examples for channel testing, and the javadocs aren't of much help either, but my IDE is showing me some classes that seem to be meant for unit testing a local channel service; I just can't figure out how to use them.

Does anyone have any experience or examples testing the GAE Channel Service?

解决方案

The following has worked for me:

import unittest

from google.appengine.api import channel
from google.appengine.ext import testbed


class TestCase(unittest.TestCase):

  def setUp(self):
    self.testbed = testbed.Testbed()
    self.testbed.activate()
    self.testbed.init_channel_stub()

  def test_send(self):
    channel_stub = self.testbed.get_stub('channel')
    token = channel.create_channel('ClientID1')
    channel_stub.connect_channel(token)
    channel.send_message('ClientID1', 'hello')
    channel_messages = channel_stub.get_channel_messages(token)
    channel_stub.clear_channel_messages(token)
    self.assertEquals(['hello'], channel_messages)


if __name__ == '__main__':
  unittest.main()

You can also look at the source code for the channel service stub.

这篇关于如何单元测试AppEngine渠道服务?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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