3 Scarily Easy Testing Tips

[article]
Summary:
In the “spirit” of Halloween, here are three scarily easy testing tips that will help you find defects in your software under test. These tips will help you easily test an app's power usage, search for a particular term in a dynamically generated URL, and verify a form's checkbox has a checkmark. After all, it’s our job as testers to make sure using our software is a treat, not a trick.

In the “spirit” of Halloween, I conjured up three scarily easy testing tips that will help you find defects in your software under test. It’s our job as testers to make sure using our software is a treat, not a trick.

1. Testing an App’s Power Usage

Let’s start with testing the power usage of mobile apps on smartphones and tablets. A mobile app that drains the battery reduces the quality of the app, making people more likely to uninstall it. It’s important to test your app’s energy efficiency, and there’s a scarily easy way to do it.

Depending on the operating system version, you typically can check the power consumption of apps like this:

iOS:

  1. Tap the Settings icon.
  2. Tap the Battery button.
  3. Under Battery Usage, you can see the percentage of power used by each app.
  4. Tap the circular Power Gauge icon on the right side of the screen (the icon that looks like an analog clock) to see a detailed breakdown of the on-screen and background power usage of each app. On-screen power usage is the amount of energy used to light up the screen. Background power usage is the amount of energy used to run the computer processor and transmitters (Wi-Fi, Bluetooth, etc.).

Android:

  1. Swipe down the panel at the top of the screen.
  2. Tap the Settings icon (the one that looks like a round gear).
  3. Tap the More button.
  4. Tap the Battery button to see the percentage of energy usage for each app since the last full charge.

For example, if an app is designed to stop all activity when not on screen, you can test this by starting the app, then closing the app and immediately noting the percentage of power consumed. After a period of time—say, twenty-four hours later—check the app’s power usage again and see if there has been additional energy consumption since the last time the app was closed. If there has been an additional power drain, then that is a bug. Any unwanted activity in the app should be fixed.

In general, if a mobile app is using a high amount of power despite limited usage of the app, that is an issue that needs to be addressed.

2. Searching for a Particular Term in a Dynamically Generated URL

For the automation testers out there, here is a tip that will improve the versatility of your tests by using Selenium WebDriver, an open source software for automating website testing using programming code. It works with seven different programming languages, but the most commonly used language with Selenium is Java, so Java is used in this tip.

Although Selenium WebDriver can be used on its own to create tests, in actual practice, Selenium WebDriver is often paired with a testing framework designed to simplify a broad range of testing needs, such as allowing tests to be easily grouped to run in a specific order, or to exclude tests. In this example, we will use the open source framework TestNG.

There are situations when you will only know a portion of information ahead of time about an expected result in a test case, such as with dynamically generated URLs, in which a portion of the URL is constantly changing and cannot be predicted. Here’s how you can search the URL of a webpage to see if it contains a particular search term.

In the example below, the search term we want to find is “website.com.” We’re going to construct a test to pass even if the URL contains other random characters—we just want to be sure “website.com” is contained somewhere in the URL.

The Java programming language has a contains() method that can search for a smaller block of text—a substring—inside a larger block of text, or string. Using this contains() method, we can find “website.com” within a larger URL with this code:

@Test // This is TestNG code that tells the framework that the code below is a test.
public void testSearchURL () {
                  String url = driver.getCurrentUrl(); // This obtains a string representation of the current URL.
                  System.out.println("url: " + url); // This prints the entire URL to console.
                  // Verify that the URL contains the portion of text that can be expected.
                  // We use TestNG’s assertTrue() method to accomplish this verification.
                  Assert.assertTrue(url.contains("website.com"));
}

This code prints the entire URL to console so we can read the results of the code manually:

url: http://www.website.com/234/abc.html

Even though the entire URL contains portions that are dynamically generated (“/234/abc”), the portion of the URL that can be predicted (“website.com”) is found and the test passes, as summarized on the console:

PASSED: testSearchURL

3. Verifying a Form’s Checkbox Has a Checkmark

When testing websites, sometimes you will want to test whether a checkbox in a form has a checkmark. You can use Selenium WebDriver to test whether the HTML attribute that creates the checkmark is null or not null.

In this code sample, we verify that the checkbox with the ID “the_id” has an HTML attribute named “checked.” If it does, then the test passes.

@Test
public void testCheckbox() {
                  WebElement checkbox = driver.findElement(By.id("the_id")); // This finds the checkbox.
                  // The line below asserts that the checkbox is checked.
                  // We use TestNG’s assertNotNull() method to accomplish this verification.
                  Assert.assertNotNull(checkbox.getAttribute("checked"));
}

These three simple test techniques add versatility to your repertoire and improve the effectiveness of your testing. After all, you don’t want your software to behave as if it’s haunted. Happy Halloween!

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.