Home Download Buy Blog Forum Support

SublimePluginTesting package

SublimePluginTesting package

Postby guillermooo on Sun May 02, 2010 1:32 pm

Get it from here: https://guillermooo@bitbucket.org/guill ... gintesting

This is a very experimental package to enable users to test plugins easily.

Basically, it sets up an environment where you can use unittest to test your plugin's code.

Currently it doesn't do much, but here's how it works:

1. write your plugin. For example:

Code: Select all
import sublime, sublimeplugin

class SampleCommand(sublimeplugin.TextCommand):
    def run(self, view, args):
        sublime.statusMessage(args)

    def aTest(self, view):
        return 0



2. view.runCommand("newTestFile") (there are no keybindings/menus yet, sorry)
3. write tests like so:


Code: Select all
import unittest
import sublimeunittest
#===============================================================================
#   Import your plugins and any Python lib available on your system.
#   Add your tests below this header.
#   Remember you're using your system's Python!
#===============================================================================

# sample imports
import sublime
import echoes
import sublimeplugin

class ATestCase(unittest.TestCase):
    def setUp(self):
        self.v = sublime.View()

    def testThisThing(self):
        echoes.SampleCommand().run(self.v, "hey")
        self.assertEquals("hey", sublime.MESSAGE_SINK["statusMessage"])

    def testThisoOtherThing(self):
        self.assertEquals(0, echoes.SampleCommand().aTest(self.v))

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


5. $ /Packages/<YourPackage>/tests/test.py

About 0.00000000000001 % of ST functionality is implemented, so use it mainly to test functions that don't use the ST API.
guillermooo
 
Posts: 718
Joined: Thu Jul 23, 2009 9:06 am

Re: SublimePluginTesting package

Postby willi297 on Sun Jun 06, 2010 10:42 pm

Guillermooo,

How is this package working out? I have the ST community packages at GoogleCode setup for continuous integration testing upon any checkin of code. It would be great to setup some standard way of going package testing, so that I can wire it up in the CI build.

I would also like to add support to the package wiki for linking to and/or building bitbucket packages as well, btw.

Greg
Greg Williams
Atomic Embedded, USA
http://atomicembedded.com
willi297
 
Posts: 121
Joined: Wed Nov 18, 2009 8:29 pm
Location: Grand Rapids, MI, USA

Re: SublimePluginTesting package

Postby guillermooo on Sun Jun 06, 2010 11:13 pm

Hi Greg,

This package turned out to be a really bad idea. However, I'm now using the python mock library (by Michael Foord) to test plugins and is working like a charm. I'll rewrite this package to use mock at some point.
guillermooo
 
Posts: 718
Joined: Thu Jul 23, 2009 9:06 am

Re: SublimePluginTesting package

Postby willi297 on Mon Jun 07, 2010 3:57 pm

Cool. I will be much happier having mocks. So you plan on using the mocks for mocking out ST calls as well? That would rock!

Keep me posted. I will for sure add tests for my stuff once we have something.
Greg Williams
Atomic Embedded, USA
http://atomicembedded.com
willi297
 
Posts: 121
Joined: Wed Nov 18, 2009 8:29 pm
Location: Grand Rapids, MI, USA

Re: SublimePluginTesting package

Postby guillermooo on Mon Jun 07, 2010 7:33 pm

If I'm doing it the right way, this is trivial with mock:

http://bitbucket.org/guillermooo/sublim ... s.py#cl-16

The only "problem" I've seen so far is that you need to create sublime.py and sublimeplugin.py along with your tests and stub out some classes there too. Check out the link above for an example.
guillermooo
 
Posts: 718
Joined: Thu Jul 23, 2009 9:06 am

Re: SublimePluginTesting package

Postby willi297 on Wed Jun 16, 2010 2:17 pm

Cool, thanks for the info. I'll have to get fluent with the Python mocking magic...
Greg Williams
Atomic Embedded, USA
http://atomicembedded.com
willi297
 
Posts: 121
Joined: Wed Nov 18, 2009 8:29 pm
Location: Grand Rapids, MI, USA

Re: SublimePluginTesting package

Postby guillermooo on Sun Jul 04, 2010 10:16 pm

UPDATED!

* Now it uses Michael Foord's Mock library.
* Still a work in progress, but you can check out the tests under /tests to get an idea of how this works.
* No keybinding/menu items are defined yet (and most likely won't ever be), so you have to do view.runCommand("newTestFile") or define your own.
guillermooo
 
Posts: 718
Joined: Thu Jul 23, 2009 9:06 am


Return to Plugin Announcements

Who is online

Users browsing this forum: No registered users and 13 guests

cron