Reader small image

You're reading from  Mastering Sublime Text

Product typeBook
Published inDec 2013
PublisherPackt
ISBN-139781849698429
Edition1st Edition
Right arrow
Author (1)
Dan Peleg
Dan Peleg
author image
Dan Peleg

Dan Peleg is an accomplished software engineer. As a former developer in the Israeli Intelligence Force, he holds extensive experience in both defense and robotic industries, and has previously lectured at DefCon conventions. Dan has developed unique algorithms for robotic platforms, specializes in a variety of software platforms, and currently works as the CTO for an American startup company.
Read more about Dan Peleg

Right arrow

Chapter 6. Testing Using Sublime

This chapter will teach us how to use Sublime Text for testing our code in different languages.

The following topics will be covered in this chapter:

  • Introduction to testing in Sublime Text

  • Testing in PHP development

  • Testing in Python development

  • Testing in Ruby development

Introduction to testing in Sublime Text


Every programmer makes mistakes; the difference between a good programmer and a bad programmer is that a good programmer tests their code before releasing it. This makes the programmer detect issues and bugs as soon as possible and fix them before something goes wrong. Also, the sooner we fix a bug the less time and cost it takes from us.

Sublime Text doesn't have any built-in features to help us test our code while developing in different languages, but the community has made plugins that work with standard testing packages for the most commonly used languages. We can use those plugins to ease our code-testing. We will cover the following plugins: PHPUnit for PHP, Unittest for Python, and RubyTest for Ruby.

Testing in PHP development


For the PHP developers among us who test their code using PHPUnit, Sublime has an awesome plugin to support PHPUnit known as sublime-phpunit, written by Stuart Herbert and located at http://github.com/stuartherbert/sublime-phpunit.

Knowing about PHPUnit

If you are a PHP developer and do not know what PHPUnit is, you should learn that PHPUnit is "the standard" for unit testing in PHP projects. It combines a framework that lets us easily write and run tests with the facility to analyze the results.

We can learn more about PHPUnit at https://github.com/sebastianbergmann/phpunit/ or check the full manual at http://phpunit.de/manual/current/en/index.html.

Using PHPUnit plugin for Sublime

Before using this plugin, we must have PHPUnit installed and functional in our project and know how to use it, a topic which is not covered here. We'll then need to download and install the PHPUnit plugin using Package Control. Let's open up the command palette by pressing Ctrl + Shift ...

Testing in Python development


Python offers us unittest, an official unit testing framework for Python, sometimes referred as PyUnit. It's like a Python version of JUnit for Java and written by Kent Beck and Erich Gamma.

Tip

For more information on how to use unittest, visit: http://docs.python.org/2/library/unittest.html

Currently the best package that helps us write Python unit tests is called sublime-unittest written by Samuel Martin, which can be found at https://github.com/martinsam/sublime-unittest.

Using unittest for Sublime

Python's unittest for Sublime is a package that contains a number of useful snippets to ease our unittest writing. To install the package, we'll use Package Control. Let's open the command palette by pressing Ctrl + Shift + P in Windows or Linux and Command + Shift + P in OS X. Then choose Install Package and install the Unittest (python) package.

The installed package has two main snippets:

  • testclass: This will create a new test class for us to fill out

    class [Foo...

Testing in Ruby development


Ruby also has its built-in unit testing library called Test::Unit, but most people like using Behavior-Driven Development (BDD) when using Ruby, and Rails especially. There are two popular BBD frameworks: RSpec and Cucumber.

Quote from the RSpec.info website:

"RSpec is a testing tool for the Ruby programming language. Born under the banner of Behavior-Driven Development, it is designed to make Test-Driven Development a productive and enjoyable experience."

Quote from the Cucumber repository:

"Cucumber is a tool that executes plain-text functional descriptions as automated tests."

We are lucky that there is a single package for Sublime that supports the three testing frameworks: Test::Unit, RSpec, and Cucumber. It's called RubyTest and can be found on https://github.com/maltize/sublime-text-2-ruby-tests.

Tip

The package is called sublime-text-2-ruby-tests but it supports both Sublime Text 2 and 3.

Using RubyTest for Sublime

To install the RubyTest package, we'll use Package...

Summary


In this chapter, we learned how to test our PHP, Python, and Ruby code using the best Sublime plugins.

In the next chapter, we will learn how to debug our PHP, JavaScript, and C/C++ code using the best plugins, all without leaving the Sublime environment!

lock icon
The rest of the chapter is locked
You have been reading a chapter from
Mastering Sublime Text
Published in: Dec 2013Publisher: PacktISBN-13: 9781849698429
Register for a free Packt account to unlock a world of extra content!
A free Packt account unlocks extra newsletters, articles, discounted offers, and much more. Start advancing your knowledge today.
undefined
Unlock this book and the full library FREE for 7 days
Get unlimited access to 7000+ expert-authored eBooks and videos courses covering every tech area you can think of
Renews at $15.99/month. Cancel anytime

Author (1)

author image
Dan Peleg

Dan Peleg is an accomplished software engineer. As a former developer in the Israeli Intelligence Force, he holds extensive experience in both defense and robotic industries, and has previously lectured at DefCon conventions. Dan has developed unique algorithms for robotic platforms, specializes in a variety of software platforms, and currently works as the CTO for an American startup company.
Read more about Dan Peleg