Application of Unit Test

Source: Internet
Author: User

I did a test on the white box test last week, and what is the white box test?

White Box Test: Also known as structural testing, it is generally used to test the internal structure of the program (Control flow, Data flow). and determine whether the results are consistent with the expected results.Types of white box testing: Static analysis Test (static parse Test,code inspection), Statement Branch Overlay test (Ctrl Flow test), and so on. At the beginning of the experiment, we didn't know how to do it, so I made a white-box test of a simple app by referring to the textbook on the Internet.

Test project name: Leap year tester

Version Number: 1.0

Test Project Description: By entering the year to determine whether it is a leap year, easy for people to use

Test Purpose: Test the program to determine whether the condition is correct, whether to take into account the situation of illegal input

Test Date: April 20, 2014

Test Person: Pambo

Test environment: Windows8+visual studio2013

Operation Steps:

1. In Solution Explorer, select the solution name, choose Add from the shortcut menu, and then select New Project. In the New Project dialog box, expand installed, Visual C #, and then select Windows Store. Then select Unit Test Library (Windows Store application) from the list of project templates

2. Open UnitTest1.cs in the Visual Studio editor.

3. Insert some test code in the TestMethod1 of the UnitTest1.cs file

Verify that tests are running in Test explorer


4. On the Test menu, select Run, and then select Run All.


5. Add a reference to the APP4 application to the Rootertests project.

    1. In Solution Explorer, select the Rootertests project, and then select Add Reference ... on the shortcut menu.
    2. On the Add Reference-rootertests dialog box, expand Solution, and then select Project. Then select the "APP4" project.

6. Add a using statement to the UnitTest1.cs file:

    1. Open UnitTest1.cs.

2. In using Microsoft.VisualStudio.TestPlatform.UnitTestFramework; Line, add the following code:

7. Add a test that uses the Rooter function. Add the following code to the UnitTest1.cpp:

8. Build a solution.

The new test is displayed in the not Run Tests node of Test Explorer.

In Test Explorer, select Run All.

Test Case:

Use Case number

Input

Expected output

Actual output

Overwrite path

Whether to pass the test

1

2000

The year is leap years

The year is leap years

1-2-4-5-6

Pass

2

2001

The year is not leap years

The year is not leap years

1-2-4-5-7

Pass

3

1000

The year is not leap years

The year is not leap years

1-2-4-5-7

Pass

4

1925

Wrong input

Wrong input

The

Pass

5

Abcd

Wrong input

Wrong input

The

Pass

Output Result:


Test Source:

MainPage.xaml.cs

1

2 using System;

3 using System. Collections. Generic;

4 using System. IO;

5 using System. Linq;

6 using System. Runtime. InteropServices. Windowsruntime;

7 using Windows. Foundation;

8 using Windows. Foundation. Collections;

9 using Windows. UI. Xaml;

Ten using Windows. UI. Xaml. Controls;

One-by- one using Windows. UI. Xaml. Controls. Primitives;

using Windows. UI. Xaml. Data;

using Windows. UI. Xaml. Input;

using Windows. UI. Xaml. Media;

using Windows. UI. Xaml. Navigation;

16

17

18

19

20

//??? E??? E????? Http://go.microsoft.com/fwlink/?linkid=234238ä??? ???

22

namespace App4

{

///<summary>

26///?? What's up?? È?? È???? È?? È?? Frame é????? E???

</summary>

Sealed partial class MainPage : Page

{

Public MainPage()

{

This . InitializeComponent();

+ }

34

Private void textbox_textchanged(object sender, textchangedeventargs e)

$ {

PNS }

$ private void textbox_textchanged_1(object sender, textchangedeventargs e)

A. {

40

*

42

Button_Click private void (object sender, RoutedEventArgs e)

{

String year = textbox. Text;

46

47

Rooter rr = new Rooter();

TextBox1. Text = rr. Isleap(year);

50

51

52

+ }

54

+ }

56

57

+ + }

59

60

Rooter.cs

1 using System;

2 using System. Collections. Generic;

3 using System. Linq;

4 using System. Text;

5 using System. Threading. Tasks;

6

7

8 namespace App4

9 {

public class Rooter

Each {

Public Rooter()

{

+ }

Isleap string(string year)

16

+ { string Shuchu;

Try

{

int year1 = Int32. Parse(year);

21st

if ((year1 % 4 = = 0 && year1 % !! = 0) | | Year1 % = = 0)

% {

Shuchu = "è???? É??? " ;

25

+ }

Else

{

Shuchu = "È??? ??? É??? " ;

30

+ }

+ }

catch (FormatException)

{

Shuchu = "è???? È?? " ;

36

37

-- }

Shuchu return ;

40

*

*

43

/+ }

UnitTest1.cs

1 using System;

2 using System. Collections. Generic;

3 using System. Linq;

4 using System. Text;

5 using Microsoft. VisualStudio. Testplatform. Unittestframework;

6 using App4;

7

8 namespace UnitTestLibrary1

9 {

Ten [TestClass]

public class UnitTest1

{

[TestMethod]

Public void TestMethod1()

{

Rooter rr = new Rooter();

* String Year = "a";

String Shuchu = rr. Isleap(year);

String Expect = "è???? É??? " ;

Assert. AreEqual(shuchu, expect);

+ }

22

(+ }

+ }

Application of Unit Test

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.