iOS测试套件 - 添加整个项目源以进行测试

时间:2018-02-02 12:15:22

标签: ios swift xcode unit-testing cocoapods

当我开始使用测试套件时,我意识到(假设我没有做错什么),我必须手动添加我想在测试套件中使用的所有源。

即:如果在我的主项目中我有procedure TfrmMain.btnLocateClick(Sender: TObject); var d: TDateTime; tblLog: TADOTable; begin // ThousandSeparator := ' '; DecimalSeparator := '.'; DateSeparator := '/'; ShortDateFormat := 'dd/mm/yyyy'; LongDateFormat := 'dd/mm/yyyy'; TimeSeparator := ':'; ShortTimeFormat := 'hh:mm'; LongTimeFormat := 'hh:mm'; TwoDigitYearCenturyWindow := 50; ListSeparator := ';'; // tblLog := TADOTable.Create(Application); try // tblLog.ConnectionString := 'Provider=SQLOLEDB.1;'+ 'Password=xxxx;'+ 'Persist Security Info=True;'+ 'User ID=xxxxxxxx;'+ 'Initial Catalog=xxxxxxxxx;'+ 'Data Source=127.0.0.1\xxxxxxx,1066'; tblLog.TableName := '[tlog]'; tblLog.Open; // First try - locate with exact value. NOT WORKING. d := StrToDateTime('26/10/2015 17:13:36.597'); if tblLog.Locate('USERDATE', d, []) then ShowMessage('Exact value, no Locate options: Located') else ShowMessage('Exact value, no Locate options: Not located'); if tblLog.Locate('USERDATE', d, [loPartialKey]) then ShowMessage('Exact value, with Locate options: Located') else ShowMessage('Exact value, with Locate options: Not located'); // Second try - locate with value that matches format settings. NOT WORKING. d := StrToDateTime('26/10/2015 17:13'); if tblLog.Locate('USERDATE', d, []) then ShowMessage('Hours and minutes, no Locate options: Located') else ShowMessage('Hours and minutes, no Locate options: Not located'); if tblLog.Locate('USERDATE', d, [loPartialKey]) then ShowMessage('Hours and minutes, with Locate options: Located') else ShowMessage('Hours and minutes, with Locate options: Not located'); // Locate with date only value. WORKING. d := StrToDateTime('02/02/2018'); if tblLog.Locate('USERDATE', d, []) then ShowMessage('Located') else ShowMessage('Not located'); finally // tblLog.Close; tblLog.Free; end; end; ,我必须转到MyClass.swift并添加我想要编译的所有资源。

另外,如果不进入Test target > Build Phases > Compile Sources并添加Test target > Build Phases > Link Binary With Libraries,我就无法在那里看到我的Cocoapods框架。

我只是想知道这是否是我们经常要做的事情。

2 个答案:

答案 0 :(得分:2)

您根本不需要添加源。

在每个测试文件的顶部。导入模块进行测试。

因此,如果你的应用名称是UIKitTesting,你可以像这样导入它

@testable import UIKitTesting

答案 1 :(得分:0)

对于测试,您需要包括要在测试时使用的Pod。 使用Kingfisher拍摄图像的示例,您需要使用该框架进行测试,需要在pod文件中添加po。

在pod文件下面,添加要测试的pod:

[ {
  "maBN" : 1,
  "name" : "Anna Statham",
  "address" : "American",
  "people" : null
}, {
  "maBN" : 2,
  "name" : "Jason Statham",
  "address" : "American",
  "people" : null
}, {
  "maBN" : 3,
  "name" : "Lyna Statham",
  "address" : "American",
  "people" : null
}, {
  "maBN" : 4,
  "name" : "John Statham",
  "address" : "American",
  "people" : null
}, {
  "maBN" : 5,
  "name" : "Alex Statham",
  "address" : "American",
  "people" : null
}, {
  "maBN" : 6,
  "name" : "Will Statham",
  "address" : "American",
  "people" : null
}, {
  "maBN" : 7,
  "name" : "Michael Statham",
  "address" : "American",
  "people" : null
}]