BizSpark SF Lightning Talk: "Automated Testing (Unit, Integration and Systems)" by Heine Frifeldt
-
Upload
mark-a -
Category
Technology
-
view
313 -
download
0
description
Transcript of BizSpark SF Lightning Talk: "Automated Testing (Unit, Integration and Systems)" by Heine Frifeldt
![Page 2: BizSpark SF Lightning Talk: "Automated Testing (Unit, Integration and Systems)" by Heine Frifeldt](https://reader035.fdocuments.net/reader035/viewer/2022062510/54b6983d4a7959aa3a8b4576/html5/thumbnails/2.jpg)
2
Loopt - Connecting You with the Places You Go
![Page 3: BizSpark SF Lightning Talk: "Automated Testing (Unit, Integration and Systems)" by Heine Frifeldt](https://reader035.fdocuments.net/reader035/viewer/2022062510/54b6983d4a7959aa3a8b4576/html5/thumbnails/3.jpg)
Kiln for source control, wiki and bug tracking
3
![Page 4: BizSpark SF Lightning Talk: "Automated Testing (Unit, Integration and Systems)" by Heine Frifeldt](https://reader035.fdocuments.net/reader035/viewer/2022062510/54b6983d4a7959aa3a8b4576/html5/thumbnails/4.jpg)
DB Schema in Mercurial via RedGate SQL Source Control
4
![Page 5: BizSpark SF Lightning Talk: "Automated Testing (Unit, Integration and Systems)" by Heine Frifeldt](https://reader035.fdocuments.net/reader035/viewer/2022062510/54b6983d4a7959aa3a8b4576/html5/thumbnails/5.jpg)
Unit tests via Visual Studio 2010
5
![Page 6: BizSpark SF Lightning Talk: "Automated Testing (Unit, Integration and Systems)" by Heine Frifeldt](https://reader035.fdocuments.net/reader035/viewer/2022062510/54b6983d4a7959aa3a8b4576/html5/thumbnails/6.jpg)
Continuous builds via Jenkins
6
![Page 7: BizSpark SF Lightning Talk: "Automated Testing (Unit, Integration and Systems)" by Heine Frifeldt](https://reader035.fdocuments.net/reader035/viewer/2022062510/54b6983d4a7959aa3a8b4576/html5/thumbnails/7.jpg)
Nightly Functional Tests via custom attribute
[TestMethod, ExecuteNightly]public void FacebookSearch(){
var adapter = new FacebookAdapter();
var places = adapter.Search(coords, 10000);Assert.IsTrue(places.Count() > 0);
}
7
![Page 8: BizSpark SF Lightning Talk: "Automated Testing (Unit, Integration and Systems)" by Heine Frifeldt](https://reader035.fdocuments.net/reader035/viewer/2022062510/54b6983d4a7959aa3a8b4576/html5/thumbnails/8.jpg)
Hard to test code that uses statics
public Configuration GetConfiguration(){
string[] conf = File.ReadAllLines("Config.xml");
// parse contents and construct Configuration obj
…
8
![Page 9: BizSpark SF Lightning Talk: "Automated Testing (Unit, Integration and Systems)" by Heine Frifeldt](https://reader035.fdocuments.net/reader035/viewer/2022062510/54b6983d4a7959aa3a8b4576/html5/thumbnails/9.jpg)
Constructors as like static methodsKeep them simple
public class User{
public User(int userId) {
DataProvider provider = new DataProvider();
var data = provider.GetUserInfo(userId);
…}
9
![Page 10: BizSpark SF Lightning Talk: "Automated Testing (Unit, Integration and Systems)" by Heine Frifeldt](https://reader035.fdocuments.net/reader035/viewer/2022062510/54b6983d4a7959aa3a8b4576/html5/thumbnails/10.jpg)
Hard to test code that has object initialization inside business logic
public Deal[] GetGrouponDeals(){
WebClient client = new WebClient();
// Logic to retrieve and parse the response
…}
10
![Page 11: BizSpark SF Lightning Talk: "Automated Testing (Unit, Integration and Systems)" by Heine Frifeldt](https://reader035.fdocuments.net/reader035/viewer/2022062510/54b6983d4a7959aa3a8b4576/html5/thumbnails/11.jpg)
Separate object graph from logicIe. remove new operators
public GrouponAdapter(ILooptWebClient webClient)
{_webClient = webClient;
}
public Deal[] GetGrouponDeals(){
// Use _webClient to retrieve URL…
11
![Page 12: BizSpark SF Lightning Talk: "Automated Testing (Unit, Integration and Systems)" by Heine Frifeldt](https://reader035.fdocuments.net/reader035/viewer/2022062510/54b6983d4a7959aa3a8b4576/html5/thumbnails/12.jpg)
Dependency injection Test able code
[TestMethod]public void VerifyDeals(){
var testClient = new TestWebClient();
var groupon = new GrouponAdapter(testClient);
// Now you control the URL response…
}
12
![Page 13: BizSpark SF Lightning Talk: "Automated Testing (Unit, Integration and Systems)" by Heine Frifeldt](https://reader035.fdocuments.net/reader035/viewer/2022062510/54b6983d4a7959aa3a8b4576/html5/thumbnails/13.jpg)
Root of application will have logic to construct object graphs
public CoreService(IDealManager dealManager,IUserManager userManager,…
public DealManager(IGrouponAdapter grouponAdapter,IDataProvider dataProvider,IPoiController poiController)
13
![Page 14: BizSpark SF Lightning Talk: "Automated Testing (Unit, Integration and Systems)" by Heine Frifeldt](https://reader035.fdocuments.net/reader035/viewer/2022062510/54b6983d4a7959aa3a8b4576/html5/thumbnails/14.jpg)
Use “Ninject” to construct object graph
…_kernel.Get<GrouponAdapter>();…
14
![Page 15: BizSpark SF Lightning Talk: "Automated Testing (Unit, Integration and Systems)" by Heine Frifeldt](https://reader035.fdocuments.net/reader035/viewer/2022062510/54b6983d4a7959aa3a8b4576/html5/thumbnails/15.jpg)
Use “Ninject” to construct object graph
…
Bind<ILooptWebClient>().To<LooptWebClient>();…
15
![Page 16: BizSpark SF Lightning Talk: "Automated Testing (Unit, Integration and Systems)" by Heine Frifeldt](https://reader035.fdocuments.net/reader035/viewer/2022062510/54b6983d4a7959aa3a8b4576/html5/thumbnails/16.jpg)
“Moq” as object mock framework
[TestMethod]public void VerifyDeals(){
var testClient = new Mock<ILooptWebClient>();testClient.
Setup(c => c.GetUrl(It.IsAny<Uri>())).Returns(Resources.MyResponse);
var groupon = new GrouponAdapter(testClient);
…} 16
![Page 17: BizSpark SF Lightning Talk: "Automated Testing (Unit, Integration and Systems)" by Heine Frifeldt](https://reader035.fdocuments.net/reader035/viewer/2022062510/54b6983d4a7959aa3a8b4576/html5/thumbnails/17.jpg)
Manage packages via NuGet
17
![Page 18: BizSpark SF Lightning Talk: "Automated Testing (Unit, Integration and Systems)" by Heine Frifeldt](https://reader035.fdocuments.net/reader035/viewer/2022062510/54b6983d4a7959aa3a8b4576/html5/thumbnails/18.jpg)
Queries into log files via Splunk
18
![Page 19: BizSpark SF Lightning Talk: "Automated Testing (Unit, Integration and Systems)" by Heine Frifeldt](https://reader035.fdocuments.net/reader035/viewer/2022062510/54b6983d4a7959aa3a8b4576/html5/thumbnails/19.jpg)
Key benchmarks on TV screen via Gecko Board
19
![Page 20: BizSpark SF Lightning Talk: "Automated Testing (Unit, Integration and Systems)" by Heine Frifeldt](https://reader035.fdocuments.net/reader035/viewer/2022062510/54b6983d4a7959aa3a8b4576/html5/thumbnails/20.jpg)
Tool Resources
• Source Control – Mercurial via Kiln• http://www.fogcreek.com/kiln/
• SQL Tools - Redgate SQL Source Control / SQL Compare• http://www.red-gate.com/products/sql-development/
• Automated Build Environment – Jenkins• http://jenkins-ci.org
• Dependency Injection / Testable code• http://misko.hevery.com/2008/11/11/clean-code-talks-dependency-injection
• Dependency Injection Framework – Ninject• http://ninject.org
• Mock Framework – Moq• http://code.google.com/p/moq
• Library extension for Visual Studio – Nuget• http://nuget.org
• Log file Index and Parser – Splunk• http://www.splunk.com
• Engineering dashboard – Gecko board• http://www.geckoboard.com
20