2012-12-03 21 views
1

我試圖嘗試在Xcode 4.4新的單元測試(對我來說是新的,因爲我以前使用OHUnit)。石英核心干擾運行單元測試

我有幾個類我添加到目標,但其中一個參考QuartzCore。

顯然我聯繫我的單元測試目標到QuartzCore框架,但它無法運行:

Undefined symbols for architecture armv7s: 
    "_CGBitmapContextCreateImage", referenced from: 
     -[UIImage(Additions) imageWithShadow] in UIImage+Additions.o 
    "_CGContextDrawImage", referenced from: 
     -[UIImage(Additions) imageWithShadow] in UIImage+Additions.o 
    "_CGBitmapContextCreate", referenced from: 
     -[UIImage(Additions) imageWithShadow] in UIImage+Additions.o 
    "_CGImageGetBitsPerComponent", referenced from: 
     -[UIImage(Additions) imageWithShadow] in UIImage+Additions.o 
    "_CGImageRelease", referenced from: 
     -[UIImage(Additions) imageWithShadow] in UIImage+Additions.o 
    "_CGContextSetShadowWithColor", referenced from: 
     -[UIImage(Additions) imageWithShadow] in UIImage+Additions.o 
    "_CGContextRelease", referenced from: 
     -[UIImage(Additions) imageWithShadow] in UIImage+Additions.o 
    "_CGRectZero", referenced from: 
     -[UIImage(Additions) imageByScalingProportionallyToSize:] in UIImage+Additions.o 
    "_CGColorSpaceRelease", referenced from: 
     -[UIImage(Additions) imageWithShadow] in UIImage+Additions.o 
    "_CGColorSpaceCreateDeviceRGB", referenced from: 
     -[UIImage(Additions) imageWithShadow] in UIImage+Additions.o 
    ld: symbol(s) not found for architecture armv7s 
    clang: error: linker command failed with exit code 1 (use -v to see invocation) 

我的構建目標成功建立,而不是單元測試目標。

我已經嘗試創建一個空白的新項目,並添加一個文件,使用QuartzCore和我有同樣的問題。

任何人都會遇到這個問題或者有什麼有用的建議嗎?

感謝

+0

您的單元測試目標是否與您的應用程序鏈接並注入到它中? –

+0

是的。爲了弄清楚出了什麼問題,我創建了一個新項目 - 包括單元測試。運行它,它的工作原理。然後我鏈接到QuartzCore,並添加了其他項目中的一個源文件。該項目編譯,但如果我去產品>測試 - 然後失敗,找不到上述符號。 – bandejapaisa

+0

奇怪的是,我從來沒有遇到QuartzCore干擾測試的問題。你能把你的示例項目放在什麼地方嗎? –

回答

1

單元測試,你只是想測試你的應用程序的邏輯,並試圖離開了任何與UI或任何額外的類/這是沒有必要的核心邏輯框架做應用程序。要做到這一點,你可能不得不將一些邏輯移到另一個文件,而這個文件只能是最基本的代碼。基本上,不要在單元測試中輸入石英芯/使用石英芯。將您正在測試的邏輯移到另一個測試類中。

+0

謝謝,我已經知道了。我沒有測試UI,但有一件事引用了另一件事,它不會編譯沒有 - 我想知道爲什麼它不會編譯和運行測試,而不是開始修改所有代碼。測試目前甚至沒有做任何事情。 – bandejapaisa

+0

我在說的是,你不應該添加任何ocunit,不應該在那裏,因爲你會有無窮無盡的這些錯誤。您需要從該文件中提取基本邏輯並引用新的測試文件,這是執行該操作的正確方法。 –

+1

沒有文檔說QuartzCore不應該在那裏。你說得對,單元測試不應該測試UI,但這只是建議的練習。我的錯誤是,我正在鏈接一個庫,它沒有找到我鏈接的文件。更改源代碼以使測試運行不是正確的方法。 – bandejapaisa

0

將缺少的框架添加到您的測試包中。

enter image description here

正如克里斯提到的 - 這可能是一個壞主意,但有些情況下,你會真的想要一個核心圖形單元測試的情況。