Software Test sixth Week "Win8 app app white box test"

Source: Internet
Author: User

This week's study notes I want to write some of my own about the problems and feelings encountered in the experiment.

Because this was a white-box test, I decided to test the function of the app that I tested last time.

This time I'm using a unit test project to do a white-box test:

Steps to create a unit test:

1. Click "File", "Add", "New Project"

2. Select the Unit test project, Windows application

3. Right-click on the reference under the Unit test project in Solution Explorer to select Add Reference

4. Select the WIN8 application in the project under the solution to test

Next is the code section of the unit test that was written:

What I'm going to test is a string conversion-encoded function in the project, the function of which is to convert the string from gb2312 encoding to UTF8

public string Gb2312toutf8 (String str)
{
Try
{
Encoding uft8 = encoding.getencoding ("UTF-8");
Encoding gb2312 = encoding.getencoding ("GBK");
byte[] temp = gb2312. GetBytes (str);
byte[] Temp1 = Encoding.convert (gb2312, UFT8, temp);
string result = Uft8. GetString (TEMP1,0,TEMP1. Length);
return result;
}
catch (Exception ex)//(Unsupportedencodingexception ex)
{
return null;
}
}

This is the code part of the original function, and then add the following sentence in the unit test UNITTEST1.cs file to refer to the namespace of the tested project

Using this is guessing riddles game;

And then we write the test function, and I write the TestMethod1:

public void TestMethod1 ()
{
Gamepage GP = new Gamepage ();
String str = "guessing riddles";
Encoding uft8 = encoding.getencoding ("UTF-8");
Encoding gb2312 = encoding.getencoding ("GBK");
byte[] temp = gb2312. GetBytes (str);
byte[] Temp1 = Encoding.convert (gb2312, UFT8, temp);
string result = Uft8. GetString (temp1, 0, Temp1. Length);


String output = GP. Gb2312toutf8 (str);
Assert.AreEqual (result, output);
}

In this function, create a test case to test whether the function is as expected, and then do it yourself. The encoded conversion is saved to

In string result, an assertion is created to determine whether the output of the function in the unit test is consistent with the expected result result.

Then I ran the unit test project, and the result was this:

Then I went to find out why, and finally I summed up the reason for the result:

I think this is because the test project itself is a WIN8 application, and the class files are all class files that control the layout, that is, the class of the UI object.

So after the run will be prompted to use the UI of the coding test, rather than unit testing, to solve this problem can only be replaced by a function of their own class WIN8 application,

But everyone writes about the WIN8 application that is embedded in the layout class, so it's impossible to solve the problem.

White-Box testing of the Win8 app app for the sixth week of software testing

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.