Fit for. NET (3)

Source: Internet
Author: User

The usage of FIT is briefly described above (see FIT. NET (0), FIT. NET (1) fit. NET (2). In the next article, I will detail the usage of FIT. due to the constant updates of FIT, its documentation is also constantly improving, so in order to get the latest information, please visit the http://fit.c2.com.

First, we will introduce ColumnFixture:

Coulmn ing the method or variable from the column of test data to the subclass.

A new Column fixture is created for each table that uses it. The same Column fixture processes each row from top to bottom and each Column from left to right. this is the example of CalculatorExample. the first method column in x () factor can be checked no matter how the Key is changed.

You can refer to the following resources:

  • Http: Release/Source/fit/Fixture. java
  • Http: Release/Source/fit/ColumnFixture. java

Let's give an example to illustrate it in detail.

Here is an example of arithmetic. This arithmetic includes addition, subtraction, multiplication, division.

We can write test cases as (in the form of tables ):

Eg. ArithmeticColumnFixture
X Y Plus () Times () Divide () Floating ()
2 3 5 6 0 0.6666667
0 0 0 0 Error Error
0 0 0 0
200 300 500 60000 0 0.6666667
2 3 10 10 10
200 3 5 6 0 0.6666667
2 -3 -1 -6 -0 -0.6666667

Then write the code for loading the FIT framework:
1 // Copyright (c) 2002 cunnhan & cunnhan, Inc.

2 // Released under the terms of the GNU General Public License version 2 or later.

3

4 using System;

5 using fit;

6
7 namespace eg

8 {

9 public class ArithmeticColumnFixture: ColumnFixture

10 {

11
12 public int x;

13 public int y;

14
15 public int plus ()

16 {

17 return x + y;

18}

19
20 public int minus ()

21 {

22 return x-y;

23}

24
25 public int times ()

26 {

27 return x * y;

28}

29
30 public int divide ()

31 {

32 return x/y;

33}

34
35 public float floating ()

36 {

37 return (float) x/(float) y;

38}

39

40 public ScientificDouble sin (){

41 return new ScientificDouble (Math. Sin (toRadians (x )));

42}

43
44 public ScientificDouble cos (){

45 return new ScientificDouble (Math. Cos (toRadians (x )));

46}

47
48 private double toRadians (double degrees ){

49 return (degrees * Math. PI)/180d;

50}

51}

52}


The following explains:

Note the first row of the table:

Eg. ArithmeticColumnFixture

What does it mean? Look at the source code. What did you find ?, Yes, the first row of the table is the name of the class described in the source code. You may have thought of the relationship between the class method and the table.

Obviously, the x and y of the table correspond to the public int x of the Code 12 rows; The public int y of the 13 rows respectively.; (Here, x and y must be public ).

The plus (), times (), divide (), and floating () Methods behind them correspond to other methods of the class respectively.

Therefore, we can imagine that the FIT framework is actually to read the data of the customer test cases described in the form of tables into the test class, and then complete the automated test with the cooperation of NUnit.

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.