Strategies for Testing a Lightsaber (That Don’t Include the Force)

[article]
Summary:
In the Star Wars saga, those in tune with the Force wield lightsabers. Lightsabers are self-built, so each one is unique and a reflection of the personality of its creator. As a tester, I found it intriguing to think about how we would test lightsabers in our own galaxy. Let’s explore how the techniques we might use for testing lightsabers can inform our real-world testing.

In the Star Wars saga, those in tune with the Force wield their versatile lightsabers, electronic swords that emit a blade of pure, glowing energy. The lightsaber is a Jedi's most important tool, though evil Sith can also use these weapons.

Lightsabers are self-built, so each one is unique and a reflection of the personality of its creator. As a tester, I found it intriguing to think about how we would test lightsabers in our own galaxy. Let’s explore how the techniques we might use for testing lightsabers can inform our real-world testing.

The most notable quality of a lightsaber is the color of its “blade,” which is really a plasma emission. There are many different colors of blades, but the Jedi typically have blue or green and the Sith usually wield red.

Jedi rely on the mystical Force, an energy field that surrounds and penetrates all living beings and binds the Star Wars galaxy together, to guide them in choosing a Force-attuned kyber crystal harmonious with their inner selves. The kyber crystal focuses the energy of the lightsaber into the blade, so each crystal determines the color of the lightsaber blade.

How would testers test for blade color in the real world? After all, everyone sees shades of color slightly differently. Some people have color blindness, which prevents them from seeing some colors that can be detected by others.

If we’re testing the color of a web element on a webpage, we can use computer software rather than the Force. Software such as Selenium WebDriver allows us to objectively determine a color in, for example, a block of text without bias from subjective color perception.

This color attribute can be expressed as an RGBA color value—red, green, blue, and alpha. The red, green, and blue parameters determine the amount of those colors combined that make up the web element, and the alpha parameter specifies the opacity of the color, between 0.0 (completely transparent) and 1.0 (completely opaque). For example, the color white contains the maximum amount of red, green, and blue, and you would want it to be completely opaque, so its color value is rgb(255, 255, 255, 1). Conversely, the color black, or the absence of color, has the color value rgb(0, 0, 0, 1). 

Here is an example of Selenium WebDriver code in the Java programming language using the TestNG framework, which can detect the text color of a web element with the id attribute “the_text.” The id attribute provides a unique identifier for a particular web element, which Selenium WebDriver uses to find said web element. This code also prints the color value to console and asserts that the color value returned by the code matches the expected value.

This assertion is what we are testing. Let’s say we expect the color of the text to be black, so the color value should match “rgba(0, 0, 0, 1).”

@Test

public void testGetColor() {

                  WebElement element = driver.findElement(By.id("the_text")); // This finds the web element.

                  String color = element.getCssValue("color"); // This gets the color value.

                  System.out.println("Color equals: " + color); // This prints the color value to console.

                  // Assert that the expected value of the color matches "rgba(0, 0, 0, 1)" for the color black.

                  Assert.assertEquals(color, "rgba(0, 0, 0, 1)");

}

In this scenario, the following is printed to console so we can read the results of the code manually:
Color equals: rgba(0, 0, 0, 1)

Plus the results of the entire test are summarized on the console:
PASSED: testGetColor

Lightsabers also make distinctive hums and zapping sounds as they swipe through the air, deflect fire, or connect with a target. Jedi use the Force to register noise and sound quality—when Master Yoda was training Luke Skywalker in the ways of the Force, he instructed him to feel the essence of the sounds of the various creatures on planet Dagobah—but how would we do it?

In our galaxy, a sound can be analyzed by pitch extraction using software such as Snack and WaveSurfer. These programs were created for speech research in computer science, and they can be used for a range of tasks relating to audio data.

Snack is designed to be used with a scripting language such as Tcl/Tk or Python. You can create versatile audio apps with just a few lines of code. Snack has commands for handling sound, such as playback, recording, file, and socket I/O. Snack also supports sound visualization such as waveforms and spectrograms. WaveSurfer has a graphical user interface and was built using Snack, so WaveSurfer can be easier to use for nonprogrammers. If a lightsaber vibrates in the key of E-flat, you know it needs to be recalibrated.

Jedi regularly need to use creativity and problem-solving skills to battle dangers and evil Sith lords. The same creativity and problem-solving abilities benefit us as testers as we face our own challenges. We may not be much of a match for a hungry, tentacled sarlacc eager to digest us as a tasty snack in its stomach for a thousand years, but we can ensure that no matter how tricky a product is, we can design tests for it.

About the author

StickyMinds is a TechWell community.

Through conferences, training, consulting, and online resources, TechWell helps you develop and deliver great software every day.