API Testing best practices

When developing your API tests, keep in mind the following types of test deliverables

1. Test plan

Best Practice: Track all your deliverables as work-items in any test management tool of your choice. This provides a great high-level view of what our API test coverage is

2. BVT’s

BVT means “Basic Verification Tests,” and they do exactly what the name implies. We use BVTs to verify that the basic functionality of a feature is solid enough to self-host the feature.

Best Practice: BVTs should be the first tests you will develop for your API set

If you do this, you’ll automatically satisfy the next best practice:

Best Practice: All public APIs should have BVTs

3. Stress Tests

The purpose of stressing an API is to ensure it doesn’t cause resource leaks, handles low-resource conditions well, and scales well to large input/data usage. The rules of test mix should follow

  • the test must not hog the CPU - give other stress apps a chance to do work
  • the test must have a cleanup mode – usually a cmd line switch you can call the app with to clean up any changes it made to the system
  • the test must be solid – check for out of memory, don’t leak, etc. Don’t cause “false positives” in the nightly stress runs
  • the test must not be focus-based
  • the test must be run in private mode alongside the regular stress mix

4. Performance

Public APIs need performance tests because it is a feature that other code depends on. By using a certain API, developers have certain expectations as to how much time and memory is required by an API.  Execution time and working set measurements are probably the most critical for an API. These two are good indicators signaling when additional investigation is necessary. The issue with performance testing is even small variations in the execution environment or test code can lead to results that are widely inconsistent, or not reliable enough to be used as a metric.

Best Practices:

  • Work with your feature team (dev/test/PM) to appropriately prioritize performance testing for your public APIs
  • Create small, focused tests that minimize outside impact for performance testing.
  • Simple unit tests or basic scenarios are better for performance monitoring
  • Ensure your tests produce consistent results

Structure of a Performance Test

  • Setup a neutral environment – ensure what you are testing is not cached in memory, or flush the process’s working set
  • Take measurements before running the test
  • Run the test/perform the action
  • Take measurements afterwards
  • Diff the results

5. Leak tests

Public APIs can cause memory and other resource leaks just like UI features can. If your APIs are leaking, you’ll generally notice this while running your stress tests. However, just knowing that something leaked doesn’t really help you debug what leaked. If you use the standard test harnesses, you can use the built-in leak testing functionality to generate logs of leaked allocations and resources while you run your tests.

Best Practice: Use the standard test harnesses to inherit basic leak testing functionality

When writing your tests, try not to cache any data as your test is running. Doing this could cause false positives when the harness is run in leak testing mode. For example, if you’re doing your own logging (which you shouldn’t be), you might be storing messages in memory & waiting until the tests are finished before dumping them to disk. If you do leak testing on a per-test basis, the leak testing code will detect your growing internal log array as a leak.

6. Boundary /Error Tests

Boundary testing is usually done after BVTs are complete and checked in. This type of testing includes calling your APIs with invalid input, NULL pointers, empty strings, huge strings, etc. Making your tests data-driven is recommended as it will be easy to add future test cases without recompiling your code.

Best Practice: Use ITE to model and automate your API system for boundary testing.

This category also includes your Security tests. For example, path strings greater than MAX_PATH characters in length, or path strings that include “::$DATA”, etc

7.  Developer regression tests

DRT means “Developer Regression Test”. Generally, these are designed and written by developers. They should be run by developers before any check-ins. The goal of DRTs is to catch heinous bugs before the build process or BVT team does.

Best Practice: Work with your developer to get DRTs written for your public APIs & identify what should be covered in those tests. Make sure he/she is running them before checkins

8. SDK samples

Sample code should be as clear and concise as possible while still conveying the prominent developer scenarios for the API & respecting solid coding practices (e.g. security checks, error checking, etc.) It is the tester’s responsibility to ensure that the sample code works properly and is included in the SDK as appropriate.

Best Practice: Make sure you test the SDK samples for your APIs on daily builds.

9. API Documentation

Part of testing public APIs is verifying that the documentation is complete, clear, and concise.

Best Practice: When writing your API tests, try copying/pasting the function definitions directly from the SDK docs

How to break software? - 15

[Me] :- Let’s look at various attacks through the operating system?

[Guruji]:- ok, while we do that let’s exclude the file system.

OS attack # 1

Exhaust the amount of physical memory

·         Does the application handle cases when no more free memory is available on the heap?

·         C/C++ coders:  When was the last time you checked if your “new” call returned null?

·         Can also test under varying amounts of memory or generating other memory faults

OS attack # 2

Inject Network Faults

·         Explore network traffic, load on a particular port, or loss of services (e.g. network is down, port unavailable)

·         Useful to examine performance

·         E.g., on versions of IE can lose current page if network shut down

Some of these system faults are difficult to generate, e.g.

·         Out of memory

·         Locked memory

·         Out of disk space

·         CRC errors

[Me] :- Do any tools exist to simulate the system software

 [Guruji]:- yes, Tester can inject faults of choosing

·         Ex. Canned HEAT or Holodeck from Florida Institute of Technology

Virtual machine, e.g. VM Ware of Virtual Server

How to break software? - 14

[Guruji]:- System Attack # 4

Assign an invalid file name

·         File names often restricted by the file system, or can exploit common standards used by the file system (long names, weird characters, etc.)

System Attack # 5

Vary file access permissions

·         Can uncover subtle bugs if apps might require most general permissions

·         Example: Web server app may not function properly unless “all” permission set to readable, but then this might compromise security

System Attack # 6

Vary or corrupt file contents

·         Simulates data being modified intentionally (perhaps maliciously) or incidentally (e.g., during transmission).  Many apps may not check for an error code

[Continued in the next day’s post]

How to break software? - 13

[Guruji]:-  System Attack # 2

Force the media to be busy or unavailable

·         A resource may be unavailable in a multi-tasking operating system

·         Does the app wait, lock, or ?

·         Typically we can look at issues such as delayed response times; may need to put up appropriate delay error messages

System Attack # 3

Damage the media

·         Useful for software that should work despite damaged media, or software that should at least detect that there was a problem with the file

·         Dust, dirt, scratches, magnetic scrambling

 

[Continued in the next day’s post]

How to break software? - 12

[Me] :- That was really helpful. So what are the System Interface Attacks?

[Guruji]:- ok, First let’s look at attacks through the file system. The Inputs from the file system similar to inputs from the user, but often even worse since many apps expect user input to be weird, but files often expected to be consistent with some specified format. And there are some Media Based Attacks wherein we simulate problems with the storage media, e.g. failure in the disk. There is this File Based Attacks where there are Problems with properties of a particular file.

[Me] :- Wow!!! Can you help me with examples like what you did in the previous attacks?

[Guruji]:- Hmn… Sure.

System Attack # 1

Fill the file system to its capacity

·         Has the developer tested for this potential problem? 

·         A crash would be undesirable when the user has the chance to free up some space to allow execution to continue

[Continued in the next day’s post]

Stress Testing

[Me]:- Guruji, What is Stress Testing?

[Guruji]:- Stress test is targeted to find issues with stability and robustness of the product, such as AVs, resource leaks, deadlocks, and various issues/inconsistency under the stress/load condition.

[Me]:- How do we run stress tests?

[Guruji]:- Most time stress tests are running in combination with other diagnostic utility such as debugger, page heap, any fault injection tools/instrumentations, performance monitor, and all other necessary tracing and logging tools that deemed to be useful for debugging and analysis. These are crucial information for developer and tester for analyzing the final outcome of the results. Feature validation is important part of the stress, though it is sometimes not done as much as it should.

[Me]:- So what are the good practices for Stress Testing?

[Guruji]:- As a good practice, all stress run should implement feature validation to ensure the system behave consistently under the load condition. Stress tests should also focus on negative conditions. Systems tend to work fine when everything is tested for valid conditions and tends to become unstable when the error paths are hit. It is very important that these error conditions are included in the stress scenarios.

Stress test need to be clear on:

·         What is the objective of the test? What for, why do you want to do it?

·         What is the key primitive/action that is targeted to?  And the code path it covers?

·         How it related to release criteria/customer impact? Duration of the runs?

·         Stability of the runs, and issues/bugs: AVs, leaks, deadlocks, or data integrity issues, or any other feature inconsistency that occurred during the stress?

·         Not often done, but it is also a good practice to report the performance patterns during the stress, thought the perf number obtained in stress is tainted by the instrumentation tools we used?

·         What are location/links to dumps, perf logs, trace files …, or simply offending call stack…

·         What is the clear context under which this test is conducted? Single user or multiple concurrent users?

·         Perf counters that record the stress run on resource utilization: CPU, Disk I/Os, memory consumption, network throughput/usage…

·         The environment parameter

·         What is the hardware used? in which the results obtained? Large customer sets/data center

www.CodeNirvana.in

Powered by Blogger.

Translate

Total Pageviews

Copyright © T R I A G E D T E S T E R