End-to-End testing in WordPress with Nightwatch.js

Nightwatch.js logo

End-to-End testing (also called e2e testing) is a really great way to make sure that your plugin or even your entire site is working the way it should.

I’ve written previously about unit testing WordPress plugins which is awesome for checking that the logic of your plugin is working as expected, whereas e2e tests simulate actual user scenarios. You can test how a real user uses your site and that everything is working as it should.

We’re using Nighwatch.js to setup e2e tests for your plugin or application. It’s not the simplest of setups, and the documentation left me scratching my head more than once. This guide will hopefully help you get started without too much pain.

Ok, ok, what do I do already?!

Nightwatch.js uses Selenium which runs a browser that will automatically run your tests. (Don’t worry if it seems a little daunting. Just keep going and it’ll all make sense at the end!).

Selenium runs on Java (yes, yes). If you’re running MacOS you can install Java using brew. If you haven’t got brew installed (why not, it’s amaze?!?!) just yet pop along to https://brew.sh/ to get started and them come back here.

Now run

brew update

followed by

brew cask install java

If you’re running Windows just head on over to https://www.java.com/en/download/help/download_options.xml and come back when you’re done.

We can install Nightwatch.js and the other stuff we need using npm.

Run this in your plugin or theme that needs testing.

npm install nightwatch selenium-server chromedriver --save-dev

or

yarn add nightwatch selenium-server chromedriver --dev

if that’s how you roll. Cool, that’s all our dependencies sorted.

Configuring Nightwatch

Now in the same directory create a file called nightwatch.conf.js and add the following code:

const seleniumServer = require("selenium-server");
const chromedriver = require("chromedriver");

module.exports = {
	"src_folders": [
		"tests/e2e" // Change this to the directory where your test are
	],
	"output_folder": "./reports", // the directory for your rest reports
	"selenium": {
		"start_process": true,
		"server_path": seleniumServer.path,
		"host": "127.0.0.1",
		"port": 4444, // selenium usually runs on 4444
		"cli_args": {
			"webdriver.chrome.driver" : chromedriver.path // There are multiple drivers you can use, eg gecko or IE
		}
	},
	"test_settings": {
		"default": {
			"globals": {
				"waitForConditionTimeout": 5000
			},
			"desiredCapabilities": {
				"browserName": "chrome"
			}
		},
		"chrome": {
			"desiredCapabilities": {
				"browserName": "chrome",
				"javascriptEnabled": true
			}
		}
	}
};

Now in the directory you specified you can write your first test!!

module.exports = {
	'Test Something' (browser) {
		browser
			.url( 'https://wordpress.org/' )
			.waitForElementVisible( '#download' )
			.click( '#download' )
			.waitForElementVisible( '.download-meta' )
			.assert.urlContains( 'download' )
			.end();
	}
};

Run the tests

./node_modules/nightwatch/bin/nightwatch

and be amazed!

Bonus!

Impress your hipster friends by adding the tests to the scripts section of your package.json.

"scripts": {
   "test": "node_modules/nightwatch/bin/nightwatch",
}

Now you can just run

npm test

every time you wish to run your tests.

For documentation on all the assertions you can use just head over to http://nightwatchjs.org/api

Caveats

Nightwatch is generally great, but I ran into occasional issues with clicking on buttons or links outside the browser viewport. It’s unclear to me whether it’s Selenium or Nightwatch that’s to blame here but whatever, it’s annoying!

I got around this by using the following (pretty nasty) workaround.

'Test Complete Order' (browser) {
	browser
		.url( 'http://lavendla.se.dev.synot.io/test/' )
		.waitForElementVisible( '.cart', 5000 )
    		.click( '.go-to-checkout' ) // This didn't work
		.execute(function() { // This DID work!
			document.querySelector('.go-to-checkout').click()
		})
    // ...test something
}

Unit Testing in WordPress – Testing integrations

Unit Testing in Wordpress

I recently wrote a post about setting up PHPUnit tests for WordPress plugins. A colleague where I work at (the most excellent Angry Creative) suggested I provide a more concrete example of how to implement Unit Tests with WordPress itself and even other plugins. Here you go!

If you haven’t read that post yet, you should probably start there.

Integrating PHPUnit Testing with WordPress

When testing integration with WordPress, a good rule of thumb is that you don’t need to test WordPress’s own APIs. WordPress is responsible for this via their own test suite. In other words, in your test class you don’t need to do this:

<?php

class MyPluginTests extends WP_UnitTestCase {
    
    /** You don't need to do this! */
    function test_something_for_no_good_reason() {
        $post_title = 'Encounter at Farpoint';
        $post_id    = wp_insert_post([
            'post_title'  => $post_title,
            'post_status' => 'publish'
        ]);

        $this->assertInternalType( 'int', $post_id );

        $post = get_post( $post_id );
        $this->assertEquals( $post_title, $post->post_title );
    }

}

Having said that, I’ve recently written tests for a plugin that imports data via a CSV file using WordPress’s APIs. In this case, I think tests are very useful to make sure that all of the data I want to import is actually imported.

Here’s an example of what I mean.

<?php

class MyPluginTests extends WP_UnitTestCase {

	/**
	 * @return array
	 */
	function data_provider() {
		return [
			'title'   => 'Babylon 5',
			'country' => 'Sweden',
			'city'    => 'Malmö',
			'address' => 'Studentgatan 4, 211 38 Malmö, Sweden',
		];
	}

	/**
	 * Test the entire data import flow.
	 */
	function test_insert_post() {
		$data     = $this->data_provider();
		$importer = new Bulk_Importer( $data );
		$post_id  = $importer->init();

		// Check the taxonomies have successfully added and attached to the post
		$countries = wp_get_post_terms( $post_id, 'country' );
		$this->assertEquals( count( $countries ), 1 );
		$this->assertEquals( $countries[0]->name, $data['country'] );

		$city = wp_get_post_terms( $post_id, 'city' );
		$this->assertEquals( count( $city ), 1 );
		$this->assertEquals( $city[0]->name, $data['city'] );

		// Check the post meta has been successfully saved
		$location = get_post_meta( $post_id, 'retailer_position', true );
		$this->assertArrayHasKey( 'address', $location );
		$this->assertArrayHasKey( 'lat', $location );
		$this->assertArrayHasKey( 'lng', $location );
		$this->assertNotEmpty( $location['lat'] );
		$this->assertNotEmpty( $location['lng'] );
		$this->assertEquals( $location['address'], $data['address'] );
	}

}

It’s not really necessary to show the ‘Bulk_Importer’ class here, but suffice to say it adds the data in the ‘data_provider’ method to the database.

The city and country fields are added as terms in 2 separate taxonomies, respectively ‘country’ and ‘city’. The address is geo-encoded via the Google Maps API and that’s handy to have tested, just to make sure my plugin logic is working the way I thought it should. The post_meta ‘retailer_position’ should look like this after it’s been imported:

[
    'address' => 'Studentgatan 4, 211 38 Malmö, Sweden',
    'lat'     => '55.6033432',
    'lng'     => '13.0050809',
];

In my tests I check that the metadata has been saved in the correct format and that the respective taxonomy terms have been appended. I can check the address is the same, but I don’t need to check the result of the Google Maps API. They are responsible for their own APIs!

Integrating PHPUnit Testing with other plugins

When you scaffold your plugin tests via WP-CLI you’ll notice a bunch of files get added to your plugin. If you look at the file at tests/bootstrap.php you’ll see something like this:

<?php

$_tests_dir = getenv( 'WP_TESTS_DIR' );
if ( ! $_tests_dir ) {
    $_tests_dir = '/tmp/wordpress-tests-lib';
}

// Give access to tests_add_filter() function.
require_once $_tests_dir . '/includes/functions.php';

/**
 * Manually load the plugin being tested.
 */
function _manually_load_plugin() {
	require dirname( dirname( __FILE__ ) ) . '/your-plugin.php';
}
tests_add_filter( 'muplugins_loaded', '_manually_load_plugin' );

// Start up the WP testing environment.
require $_tests_dir . '/includes/bootstrap.php';

Note the ‘_manually_load_plugin()’ function. If you need to load additional plugins when you run your tests just add them to the list and they be autoloaded when you run your tests.

<?php

function _manually_load_plugin() {
    require dirname( dirname( __FILE__ ) ) . '/your-plugin.php';
    require dirname( dirname( dirname( __FILE__ ) ) ) . '/woocommerce/woocommerce.php';
}
tests_add_filter( 'muplugins_loaded', '_manually_load_plugin' );

Now in my tests i can use WooCommerce’s APIs without issue.

<?php

class MyPluginTests extends WP_UnitTestCase {

    /**
     * Test that relies on WooCommerce
     */
    function test_woocommerce() {
        // Assuming the product actually exists 🙂
        $product_id = 666;
        WC()->cart->add_to_cart( $product_id );

        $this->assertNotEmpty( WC()->cart->cart_contents );
    }

}

Again remember that we don’t actually need to test WooCommerce’s APIs. They are responsible for that, this is just to demonstrate that the APIs are in fact available to us.

Setting up data before we run our tests

Often when we want to test our plugin code we will need to create actual data to work with (see the above example). You’ll probably have noticed that our plugin tests class extends WP_UnitTestCase and not PHPUnit\Framework\TestCase.

WP_UnitTestCase class has a bunch of factory objects that you can use for creating posts, attachments, terms, users, comments, blogs, categories, terms and even networks. There doesn’t seem to be any official documentation about the factory classes which is a bit rubbish if you ask me, but google turned up this gist that has some data at least.

Using the setUp and tearDown methods

In your tests class there are 2 methods that will be called before and after each test method in the class is run, namely setUp and tearDown. The setUp method is a good place to use the respective factory object methods to create any data you’ll need in your tests. You can use the factory objects to go nuts and add a bunch of data to your test database here.

<?php

class MyPluginTests extends WP_UnitTestCase {

    function setUp() {
         // Call the setup method on the parent or the factory objects won't be loaded!
        parent::setUp();

        // Accepts the same arguments as wp_insert_post
        $post_id = $this->factory->post->create([
            'post_type' => 'page',
            'post_title => 'The name of the place is Babylon 5.',
        ]);

        // Create a bunch of posts, just to have some data to play around with.
        $post_ids = $this->factory->post->create_many( 50 );

        // Create an admin user
        $user_id = $this->factory->user->create([
            'user_login' => 'test',
            'role'       => 'administrator'
        ]);

        // Create a bunch of users
        $user_ids = $this->factory->user->create_many( 4 );

        // Create a single term
        $term_id = $this->factory->term->create([
            'name'     => 'Babylon 5',
            'taxonomy' => 'category',
            'slug'     => 'babylon-5'
        ]);

        // Create a bunch of terms
        $term_ids = $this->factory->term->create_many( 10 );
    }


}

Of course, you can use the factory methods anywhere in your class.

<?php

class MyPluginTests extends WP_UnitTestCase {

    // Remember to always call the parent::setUp method to make the factory objects available.
    function setUp() {
        parent::setUp();
    }


    function test_something() {
        $post_id = $this->factory->post->create([ 'post_title' => 'Trees and people used to be good friends' ]);

        $post = get_post( $post_id );
        // Go ahead! Test something 🙂
    }

}

#protip – if you’re using custom custom taxonomies that are not created the plugin you’re testing you can create them in the setUp method so that they’re available in your tests.

<?php

class MyPluginTests extends WP_UnitTestCase {

    function setUp() {
        parent::setUp();

        register_post_type( 'book' );
        register_taxonomy( 'genre', 'book' );

        ...
    }

}

Real world example

Ok, here’s a part of some actual tests i wrote to test a discount plugin I wrote for WooCommerce. The setUp method creates the products and adds them to the cart. The tearDown method removes the products from the cart and deletes them from the database.

<?php

class MyPluginTests extends WP_UnitTestCase {

    /** @var array */
    public $products = [];

    /**
     * SetUp
     */
    public function setUp() {
        parent::setUp();

        $this->createProducts();
        foreach ( $this->products as $product_id ) {
            WC()->cart->add_to_cart( $product_id );
        }

    }

    /**
     * TearDown
     */
    public function tearDown() {
        WC()->cart->empty_cart( true );

        foreach ( $this->products as $product_id ) {
            wp_delete_post( $product_id, true );
        }
    }


    /**
     * Create the products.
     */
    public function createProducts() {
        $products = [
            [
                'title' => 'Product 500',
            ],
            [
                'title' => 'Product 400',
            ],
            [
                'title' => 'Product 300',
            ],
        ];

        foreach ( $products as $product ) {
            $this->products[] = $this->factory->post->create([
               'post_title'  => $product['title'],
               'post_type'   => 'product',
               'post_status' => 'publish',
            ]);

            // Plus a bunch more stuff to actually create a valid WooCommerce product.
            ...
         }

    }

    /**
     * WC()->cart now contains the 3 products I created, so I can do some tests on
     * manipulating the cart with 'real' data using the WC_Cart APIs.
     */
    function test_the_cart() {
        ...
    }

}

Awesome, now we can test ALL OF THE THINGS!!

Ping me at @richardsweeney if you have any questions about PHPUnit testing in WordPress. I’d be happy to help out if I can 🙂

Unit Testing in WordPress

Unit Testing in Wordpress

Unit testing in PHP is one of those things that people talk about but can be difficult to get your head around until you take the leap and actually write your first test.

It can also be difficult to see the value in taking the time to write tests if you’ve never done it before, but take my word for it – it’s one of those things that when you start writing tests you’ll wonder why the hell it took you so long to start writing tests and how you ever managed before!

I can pretty much guarantee you it will make you change the way you structure your code too, in my case very much for the better.

Getting started

First you’ll need to install PHPUnit.

composer global require phpunit/phpunit

The easiest way to add tests to a plugin is to use WP-CLI.

wp scaffold plugin-tests {plugin-name}

Check out the documentation for more details about this command.

When you’ve run the command, cd to your plugin directory and run.

./bin/install-wp-tests.sh {db-name} {db-user} {db-pass} [db-host] [wp-version] [skip-database-creation]

Just run something like the following:

./bin/install-wp-tests.sh wordrpress_tests mysql_username mysql_password

To install the test library and the tests database. Do not use a real database for this as it will be deleted when you run your tests!!

Writing your tests

Alright, you’ve made it this far! You’ll notice a couple of files added to your plugin now. Check out the default tests class at: tests/tests-sample.php. It should look like this:

/**
 * Sample test case.
 */
class SampleTest extends WP_UnitTestCase {

    /**
     * A single example test.
     */
    function test_sample() {
        $this->assertTrue( true );
    }
}

If you run

phpunit

from your plugin directory you should see something like the following:

Unit tests result

Awesome!! Now you just need to write some actual tests. Sitepoint has a pretty good introduction article about this. I suggest just playing around with the API it feels natural.

Try adding the following to your tests class and see what happens 🙂

function test_something() {
    $string = 'Nice :)';
    $this->assertEquals( 'Nice :)', $string );
}

function test_something_that_fails() {
    $string = 'Nice :)';
    $this->assertEquals( 'BAD :(', $string );
}

There’s a bunch of assertions you can use depending on your use case. They’re all detailed on the PHPUnit site.

Happy testing!

Update! I’ve since written a sort of part 2 to this post that goes a bit deeper into how to integrate your tests with WordPress and even other plugins. Check it out, if you fancy diving a wee bit deeper into the subject.

An 18th century theorbo

Weiss tablature

Choosing the right continuo instrument for the job is something that I have spent a large amount of time thinking about and a revelation about a (relatively) new theorbo has prompted me to write down some of my thoughts and observations about this very subject.

The first lute I owned was a 13 course ‘baroque’ lute in d minor tuning. As it was the only instrument I had in the beginning, I learnt to play both solo repertoire and continuo on this lute. After a few years, I bought a small English theorbo (a meagre 78cm) that I used in Italian tuning (that is to say in A with the top 2 courses at the lower octave). A few years later I upgraded to a more realistic (or historical, depending on your degree of fanaticism) Italianate theorbo with a string length of 88cm. That was better, but on occasions, if found this instrument couldn’t really make the kind of sound I wanted, especially for 18th century repertoire.

I wanted something with a brighter tone, something with more bite than the standard theorbo. I decided what I needed was an archlute. I got one, great. Problem solved..?

Old habits

When I studied in London, I often read that the archlute gradually replaced the theorbo in the 18th century as the tessitura of the bass lines went progressively higher. It’s a nice idea, but it’s not exactly true

If we look historically at where and when the archlute was really popular, we must look to Rome. In Rome we have tons of mentions of the archlute (as well as loads of obbligato parts – way more than we find elsewhere) in the 2nd half of the 17th and the first half 18th century, give or take a few decades. Corelli, Stradella, Colista, Lonati and many more all wrote obbligato parts for the archlute, as did Händel whilst in Rome. So why was the archlute so darn popular in just Rome of all places?!

It seems as though pitch is the answer. We know now that the ‘standard’ pitch in Rome at this period was low – really low. Somewhere between A = 360 and A=392.

Most of the surviving Roman archlutes have really big bodies and long string lengths (somewhere between 72 – 77cm). The vast majority of the instruments people play on today have much shorter string-lengths and smaller body sizes – with good reason: with a top string (especially in gut), there is a physical limit to how the top string on a lute can be tuned before it breaks.

At this relatively low pitch, in order to produce any kind of decent sound on the theorbo, you need a pretty massive instrument (sure enough some of the largest surviving theorbos are indeed from Rome). Where the theorbo has many disadvantages at this lower pitch, (very long string lengths, a less bright tone, etc) the archlute on the other hand gains hugely by having a longer string length and a larger body that still remains relatively easy to play.

The result will be a really big lute with a big sound and plenty of bite – especially if you play with nails, which seems to have been the norm in Italy at this time (see my earlier post about this). The problem is that an archlute at this pitch is pretty useless nowadays, with our modern pitch standard of A = 415. Unless you want an archlute in F .Try playing a Händel opera on that, go on I dare you…!

Tecchler

The archlute I commissioned (from the very gifted Ivo Magherini) was a copy of a big Roman instrument made by D. Tecchler in 1725. Ivo and I talked a lot about trying to retain the original body size, but then, like the majority of modern copies of archlutes, we decided that it would be better to scale the whole thing down a bit. We ended up with a stopped-string length of 68cm (that worked just about ok at A = 415) and a body around the size of a French small theorbo in D. It was a great lute and certainly packed a punch.

Although the copy was a great one, I think that with scaling down both the body size and string length, we lost just a bit too much oomph. In fact, being perfectly honest, although the brightness of a good archlute is almost always a very pleasing sound, I’ve never really heard or played one that had enough depth or quantity of sound to compete with a theorbo.

The ‘d minor theorbo’

It was around this time that I started considering a theorbo in d minor tuning. I spoke with Ivo about potential models and we decided to take it to the max and make a copy of the beautiful and rather massive 18th century theorbo by Schelle, currently hidden away from mortals in the basement of the museum in Nüremberg.

The d minor theorbo is an instrument described by both Baron and Weiss. According to Weiss, this type of theorbo was identical to the Italian theorbo, with the only difference being the tuning. The tuning is identical to that of the ‘baroque’ lute, minus the top string. The top string (d) is a single course, with unison double courses for the 2nd, 3rd & 4th courses and octave courses for the 5th, 6th & 7th courses (as on a ‘baroque’ lute).

Then, we’re on to the big guns: the diapasons. Courses 8 – 13 (or 14) are single diapasons tuned to either GG or  even FF. My copy of the Schelle has string-lengths of 85 / 170cm, with 13 courses, but space for a 14th. 85cm is pretty much the max string-length for a top string of D at A=415.

The point I’m trying to make here is that I think that this is the ultimate continuo lute for 18th century music (and late 17th too!). I think it’s an excellent alternative to the archlute and an instrument that I would really encourage players to try (then you can make your own minds up!). The sound is really big, bold and bright. It really carries in ensemble, primarily thanks to the rather massive body and the bass is awesome, but the sound still retains the character of a lute.

A d minor theorbo is really just a massive lute, which is really what I reckon a big archlute should sound like. The problem if we scale them down too much, they just end up sounding like small lutes.

Weiss

In a letter Weiss’ wrote to Mathesson regarding the lute as a continuo instrument, he remarks that the lute is well suited to accompanying solo cantatas as well as trios and quartets. He’s talking about chamber music. Weiss goes on to say that the theorbo is much better suited to playing with large ensembles as the lute can easily be overpowered. If one plays on small archlutes in larger ensembles, we won’t stand to produce much more sound that a decent ‘baroque’ lute, which according to Weiss, just doesn’t cut the mustard. No sir.

An idea for a modern, historical archlute

There is one further alternative worth mentioning here, but this one is a little difficult to justify historically… What about a proper, full-sized archlute tuned as a ‘baroque’ lute, that is to say in d minor? It’s unlikely that Roman archlutes were ever tuned in this way, but it would enable us today to play on a really big instrument and thus enjoy all the benefits!

Finally, if you’ve never played continuo in d minor, then you’re really missing out! It’s a fantastic, versatile tuning that may admittedly take a little getting used to, but once you’ve got your head around it, you’ll find it can cope with almost any key you can throw at it (within reason of course!).

Here’s a few pictures of this handsome beast!

d-minor theorbo

‘The best way of play’

Lute dyphone

Around 13 years ago after my end-of-year recital as a student studying classical guitar in Dublin I ceremoniously cut off the fingernails on my right hand. I had decided to become a lutenist! I preferred the music, there was more of it and the possibility of far more social music making made my choice an easy one.

Approximately 5 years ago, I decided let the nails on my right hand grow. Was I intending to take up the guitar once more and shun the lute?! The answer is no – I had decided to play the lute with nails.

At the time I didn’t consider the controversy I would cause by this decision and even today I find there is often confusion regarding the authenticity of this approach. Like most people, I hate to be judged at all, but as someone for whom historical accuracy has always been of the utmost importance to, I didn’t want to be accused of historical heresy!

So, what’s the deal? Modern guitarists play with nails, lutenists don’t (or at least shouldn’t) – right?! Let’s think about that assumption for a minute: When the 20th century lute revival began, lutes were often lightly constructed and strung with very low tension strings. A modern school of lute playing evolved, where lutenists tended to play with a technique radically different to that of the modern classical guitar. Many of the pioneers of lute playing utilized a historical technique detailed in several 16th and early 17th century sources, where the thumb of the right hand is placed inside the hand (not stretched outside the fingers, like modern guitar and harp technique). The string is then plucked using the flesh of the finger only.

In the early days of the revival, this was really what differentiated guitarists from lutenists. A generation or two later and we’re in a position to re-think the assumption that there is only one appropriate historical performance technique for the lute. Whilst the technique described above is indeed a historical technique, it is in fact only suitable for the music of the 16th and early 17th centuries and that it is only one of several different historical approaches. As the lute acquired more and more strings, this technique was gradually and universally dropped in favour of the technique of playing with the right hand thumb outside of the hand which facilitated in reaching the additional bass courses – Dowland himself changed his technique to the more modern ‘thumb out’ mid-career.

That’s all well and good, but the question remains: Can playing the lute with nails be considered a valid historical performance technique for historical plucked string instruments?

In his Intavolatura di Liuto e di Chitarrone (1632) Alessandro Piccinini advocates the use of fingernails on the right hand. In fact, some of the advanced performance techniques he describes in his book I don’t think are really possible without fingernails. One such technique is where the nail of the index finger plucks the string back and forth alternating with the front and the back of the nail in rapid succession.

Francesco Corbetta, the Italian guitar teacher to the King Louis 14th of France played with fingernails. As recorded by Adam Ebert in his Mémoires of 1723 ‘having had the bad fortune of breaking a nail, [Corbetta] was unable to play at the Festival with his consort’. In Gaspar Sanz’s Introducción de Musica sobre la guitarra (1674), the licenciado S. Alfonso writes ‘There are some who play with the nails, who ravish the senses, and others who grate the nerves’. The following picture shows that yet another guitarist, Domenico Pellegrini also played with nails.

Thomas Mace in his Musicke’s Monument of 1676 writes ‘…take notice, that you Strike not your Strings with your Nails, as some do, who maintain it the Best way of Play, but I do not, and for this reason ; because the Nail cannot draw so sweet a sound from a Lute, as the nibble end of the Flesh can do’. Mace obviously had a preference for playing without nails, but it’s also clear that it was not uncommon to play with nails.

Silvius Leopold Weiss, probably the most famous lutenist of his generation, travelled to Italy in the 18th century where he both saw and undoubtably played with many Italian lutenists. In a letter to Matheson regarding the lute and theorbo Weiss writes that the archlute and theorbo in Italy are ordinarily played with nails. Weiss – like Mace – expresses a preference for playing without fingernails, adding that that when heard at close range, the archlute and theorbo played with nails can sound harsh. Regardless, the fact remains that Weiss’ writings imply that it was in fact the exception and not the rule to play the theorbo and the archlute without nails in Italy in the 18th century.

I want to stress a couple of things at this point. Firstly and most importantly I’m not saying that it’s more correct to use this technique that any other historically justifiable performance technique – a point already indirectly made by both Weiss and Mace! My only goal is to demonstrate that playing with nails is a valid technique for historical plucked instruments. Secondly, I think it’s worth pointing out that this playing style is very different to modern guitar technique! I was a classical guitarist for several years before I played the lute and I played with nails. I also played the lute for many years without nails, so I figure I’m qualified to compare the styles!

If you’d like to hear what it sounds like when I play the theorbo with nails you can have a listen to the audio samples at https://richardsweeney.com/lute/

The pros and cons.

Over the past several years of playing with nails I’ve made some interesting observations. I’m not trying to persuade anyone to change their technique and I’m certainly not saying that it’s better to play with nails that without. I’m also sure that the results of changing techniques will vary for person to person, but for those of you that are interested, here’s some of my experiences since I started playing with nails.

The pros.

1. I can play faster. The ‘thumb-out’ technique has a reputation of being a little slower that ‘thumb-in’, but I can play much faster than I could before by using less of the flesh of my finger in the stroke and more of the nail in faster passages. If I employ Piccinini’s trick (actually it’s not just Piccinini’s trick really, the same technique is described in several 16th century Spanish vihuela sources too) of using the same finger to play fast passages, I can play really fast. It is however a bit difficult to control this and string crossings I find almost impossible!

2. I can play (a bit) louder. Using fingernails also makes the sound I produce brighter which tends to carry better in ensemble (this is all debatable I know – please remember this are just my own experiences!). Personally I find the theorbo benefits greatly from a brighter sound, but a lightly constructed lute played with nails can sound a little harsh if one is not careful. Most of my instruments are built by Ivo Magherini who doesn’t shy away from using a decent amount of wood and I think these instruments tend to sound great with nails.

3. I don’t get calluses on my fingers anymore! When I want to give a bit more, I can use a bit more nail and a bit less flesh thus saving my poor fingers.

4. Another interesting side-effect of playing with nails is that I find historical arpeggiation on the theorbo – as dictated in the lute books of Piccinini and Girolamo Kapsberger – much easier to pull off with nails. Where I often struggled in the past to play Kaspberger’s prescribed right hand fingerings I find that they are greatly facilitated with nails. (Kapsberger makes no mention of nails, or otherwise and the topic of period right hand fingerings for the Italian theorbo is at least a post in itself. It’s also one I promise to write soon!).

5. I find the strumming patterns of the baroque guitar to be considerably easier with nails and I also much prefer the sound now! This is all down to personal taste of course!

The cons.

I look ridiculous! I’m constantly ridiculed by my long-suffering 12 year old daughter Miah for polishing my nails in public (sorry Miah – such embarrassing parents..). Nails can be a pain to maintain and they can break. Once, whilst browsing through music for sale at the lute society stall at the early music exhibition in Greenwich in London I was asked if I was a curious guitarist…

As with every assumption regarding modern-day ideas of historical techniques, let’s not rest on the laurels of the pioneers! As historical performers it is our responsibility to question everything we hear, see or do. Let’s encourage people to find their own way and let’s learn to love and embrace the limitations of historical performance!

Update:

Thanks to Diego Cantalupi – http://www.diegocantalupi.it/ – for sending me the following images of Filippo Della Casa (1737–1810).

Everything you’ve always wanted to know about the theorbo but were afraid to ask

Allegory of Music

As a theorbo player I get asked lots of questions about my instrument.

Questions like:

  • What is it?
  • Where does it come from?
  • How many strings does it have?
  • Do you play all of them?
  • How is it tuned?
  • Why is it so long?
  • How, exactly, do you play it?
  • Was it a usual member of a baroque orchestra?
  • Do you ever wish you played the flute?

I do try to answer all these questions as I get asked, but for those of you who didn’t get a chance to ask, or for those who would like to know more, I’ll do my best to explain a little bit about the theorbo.

A theorbo

What is it and where does it come from?

The theorbo, one of the largest members of the lute family, was a new kind of instrument conceived in Florence during the late 16th century to accompany a new style of vocal music known as ‘stile recitativo’. Owing to its gentleness and depth of sound it was considered the perfect accompaniment for the human voice.

This theorbo was gradually adopted (and in most cases, nationalised) by every European country over the course of the 17th century. The first theorbo to reach England in the 17th century was destroyed at port as is was assumed to be a weapon!

How many strings does it have and do you play all of them?

I have two theorboes, one is a copy of a German theorbo from the 1730s. It’s got 20 strings arranged in descending order like this:

One single string at the top (ie: the highest pitched string) followed by six pairs of strings (the pairs are always played together, like on a mandolin) and seven long bass strings. I do play all of them.

My other theorbo has sixteen single strings and is a copy of an Italian instrument from 1610. This one has six strings at the top and ten long bass strings.

How is it tuned and why is it so long?

Historically there are several different tunings for the theorbo. The top five strings (ie: the five highest strings in pitch) of my 18th century theorbo are tuned to a chord of d minor and the rest are tuned in a descending scale (like a harp).

The reason why it’s so long is due to the gut strings that musicians used at that time. With any kind of string, in order to get a lower pitch you have to increase the thickness (diameter). For a gut string, the thicker the string the duller the sound. If however you could increase the length of string then you can have a thinner string for a lower note and therefore a much better sound.

Modern concert harps and grand pianos still follow this principle: the lower the note, the longer the string, therefore the quality of sound for the lower strings doesn’t deteriorate.

How, exactly, do you play it?

The long bass strings of a theorbo – also called diapasons – are played with the thumb of the right hand and are never stopped with the left hand. The top strings are played with both hands, where the left hand makes the chord shapes and the right hand plucks the appropriate strings, like a guitar. Historically, the theorbo could be played with or without fingernails.

Was it a usual member of a baroque orchestra?

Yes, we have records of many baroque orchestras that used theorboes. Corelli used as many as five, Vivaldi as many as four. Händel and his theorbo player in London read from the same score and Telemann usually had two in his orchestra.

Do you ever wish you played the flute?

Only when I’m at the airport.