Application Tests and logical tests
When adding ocunit to engineering, we mentioned that both the application test (application testing) and the logical test (Logic testing) are concepts that are not concepts in Ocunit, but in unit tests. Application testing is a test of the entire application, which takes into account factors such as the operating environment when designing test cases, such as environmental issues such as web containers and EJB containers that need to be considered when testing Java EE. The logical test is lightweight, testing only the correctness of the method or algorithm of a business logic object.
Writing Ocunit test methods
Each unit test case corresponds to a method in the test class, so the test class is divided into: the logical test class and the application test class, and the logical and application tests are different when designing test cases. Writing Ocunit test methods is also a logical test and application test. Below we also through the calculation of personal income tax application, their writing process, the test class Viewcontroller writing process is no longer introduced.
1. Logical test method
Logical testing should test the business logic of calculating personal income tax, i.e. test the calculate in Viewcontroller class: Method
The code for LogicTest.h is as follows:
#import <SenTestingKit/SenTestingKit.h> #import "ViewController.h" @interface logictest:sentestcase
@property (Nonatomic,strong) Viewcontroller *viewcontroller; @end define the Viewcontroller attribute in H file, note that the attribute parameter is set to strong. The code for LOGICTEST.M is as follows: #import "LogicTest.h" @implementation logictest-(void) setUp {[Supe
R SetUp];
Self.viewcontroller = [[Viewcontroller alloc] init];
}-(void) teardown {self.viewcontroller = nil;
[Super teardown];
//Test Month taxable amount not exceeding 1500 yuan use case 1-(void) TestCalculateLevel1 {double dbrevenue = 5000;
NSString *strrevenue = [NSString stringwithformat:@ "%f", dbrevenue];
nsstring* strtax =[self.viewcontroller calculate:strrevenue];
Stasserttrue ([strtax doublevalue] = 45, @ "Expectations are: 45 The actual value is:%@", strtax); //Test Month taxable amount exceeds 1500 to 4500 yuan use case 2-(void) TestCalculateLevel2 {double dbrevenue = 8000;
NSString *strrevenue = [NSString stringwithformat:@ "%f", dbrevenue];
nsstring* strtax =[self.viewcontroller calculate:strrevenue];
Stasserttrue ([strtax doublevalue] = 345, @ "Expectations are: 345 The actual value is:%@", strtax);
//Test Month taxable amount exceeds 4500 to 9000 yuan use case 3-(void) TestCalculateLevel3 {double dbrevenue = 12500;
NSString *strrevenue = [NSString stringwithformat:@ "%f", dbrevenue];
nsstring* strtax =[self.viewcontroller calculate:strrevenue];
Stasserttrue ([strtax doublevalue] = 1245, @ "Expectations are: 1245 The actual value is:%@", strtax);
//Test Month taxable amount exceeds 9000 to 35000 yuan use case 4-(void) TestCalculateLevel4 {double dbrevenue = 38500;
NSString *strrevenue = [NSString stringwithformat:@ "%f", dbrevenue];
nsstring* strtax =[self.viewcontroller calculate:strrevenue];
Stasserttrue ([strtax doublevalue] = 7745, @ "Expectations are: 7745 The actual value is:%@", strtax);
//Test Month taxable amount exceeds 35000 to 55000 yuan use case 5-(void) TestCalculateLevel5
{Double dbrevenue = 58500;
NSString *strrevenue = [NSString stringwithformat:@ "%f", dbrevenue];
nsstring* strtax =[self.viewcontroller calculate:strrevenue];
Stasserttrue ([strtax doublevalue] = 13745, @ "Expectations are: 13745 The actual value is:%@", strtax);
//Test Month taxable amount exceeds 55000 to 80000 yuan use case 6-(void) TestCalculateLevel6 {double dbrevenue = 83500;
NSString *strrevenue = [NSString stringwithformat:@ "%f", dbrevenue];
nsstring* strtax =[self.viewcontroller calculate:strrevenue];
Stasserttrue ([strtax doublevalue] = 22495, @ "Expectations are: 22495 The actual value is:%@", strtax);
//The test month taxable amount exceeds 80000 yuan use case 7-(void) TestCalculateLevel7 {double dbrevenue = 103500;
NSString *strrevenue = [NSString stringwithformat:@ "%f", dbrevenue];
nsstring* strtax =[self.viewcontroller calculate:strrevenue];
Stasserttrue ([strtax doublevalue] = 31495, @ "Expectations are: 31495 The actual value is:%@", strtax); } @end