Testing/XML Flashcards Preview

Cert IV Programming > Testing/XML > Flashcards

Flashcards in Testing/XML Deck (22):

Why unit test?

The main goal of the unit testing is to verify the correctness of a software unit by comparing the return value of a unit with the expected result for a different set of parameter values.


What is a software unit? (3)

  • smallest testable part of an application
  • in procedural programming, it is a function or procedure
  • in Object-Oriented programming, it is a member function or method


What are unit tests? (4)

  • each unit test tests executes a test case
  • units are tested independently of each other
  • multiple test cases per unit (one per equivalence class)
  • tedious to run all tests by hand –should be automated


What are the benefits of unit testing? (3)

  • facilitates change -automatically see if new changes break compilation
  • implicit documentation -see how the code is actually used
  • enforces interface/implementation split


Why do you refactor code for testable code design? (4)

  • to simplify code structure and its readability
  • usually involves extracting complex code into a number of well-named methods
  • does not necessarily shorten the code
  • should make individual sections of the code easier to read and maintain


Refactor the following code to make it more legible.

private void button1_Click(object sender, EventArgs e)
int num1 = int.Parse(textBox1.Text);
int num2 = int.Parse(textBox2.Text);
int total = num1 + num2;
label1.Text = total.ToString();

private void button1_Click(object sender, EventArgs e)
int num1 = int.Parse(textBox1.Text);
int num2 = int.Parse(textBox2.Text);
int total = FindTotal(num1, num2);
label1.Text = total.ToString();

private int FindTotal(int num1, int num2)
int total = num1 + num2;
return total;


What are the testing frameworks for C++?

  • Boost.Testinglibrary
  • CPPUnit
  • CxxUnit


What are the testing frameworks for NET languages?

  • Nunit
  • xUnit.net
  • MbUnit
  • QuickUnit.net
  • csUnit


What is the testing framework for Java?



List the Visual Studio 2012 test tools. (4)

  • Test Explorer
  • Microsoft unit test framework for managed code and C++
  • Code coverage tools
  • Microsoft Fakes isolation framework


What does the Test Explorer in Visual Studio do?

It lets you run unit tests and view their results.


What does the Microsoft unit test framework for managed code and C++ do?

It provides a framework for testing .NET code and native code.


What do Code coverage tools do?

They determine the amount of product code that your unit tests exercise.


What does the Microsoft Fakes isolation framework do?

It creates substitute classes and methods for the code under test.


All the methods and classes generated for the automated unit testing are inherited from the namespace ...



What are the general steps to take in unit testing? (4)

  • Create a unit test project
  • Add a reference to the code project under test
  • Write the test
  • Build and run the test


•The AAA (...) pattern is a common way of ... for a method under test.

Arrange, Act, Assert

writing unit tests


What happens at the Arrange stage of unit testing?

It initializes objects and sets the value of the data that is passed to the method under test.


What happens at the Act stage of unit testing?

The Act section invokes the method under test with the arranged parameters.


What happens at the Assert stage of unit testing?

The Assert section verifies that the action of the method under test behaves as expected.


What do Test Explorer views do?

  • display all of your tests, or only the tests that have passed, failed, haven’t been run yet, or have been skipped
  • filter the tests by matching text in the search box at the global level or by selecting one of the pre-defined filters
  • run any selection of the tests at any time



[TestMethod()]is required in the Microsoft unit testing framework for managed code for any class that contains unit test methods that you want to run in Test Explorer.

[ClassInitialize()]: to run code before running the first test in the class
[ClassCleanup()]: to run code after all tests in a class have run
[TestInitialize()]: to run code before running each test
[TestCleanup()]: to run code after each test has run