YOUR FEEDBACK
The Cloud Wars - Is Guitar Hero a Cloud?
Roland Judas wrote: I am following the cloud discussions for some months n...


2007 West
GOLD SPONSORS:
Active Endpoints
Your SOA Needs BPEL for Orchestration
BEA
Virtualized SOA: Adaptive Infrastructure for Demanding Applications
Nexaweb
Overcoming Bandwidth Challenges with Nexaweb
TIBCO
What is Service Virtualization?
SILVER SPONSORS:
WSO2
Using Web Services Technologies and FOSS Solutions
Click For 2007 East
Event Webcasts

2008 East
PLATINUM SPONSORS:
Appcelerator
Think Fast: Accelerate AJAX Development with Appcelerator
GOLD SPONSORS:
DreamFace Interactive
The Ultimate Framework for Creating Personalized Web 2.0 Mashups
ICEsoft
AJAX and Social Computing for the Enterprise
Kaazing
Enterprise Comet: Real–Time, Real–Time, or Real–Time Web 2.0?
Nexaweb
Now Playing: Desktop Apps in the Browser!
Sun
jMaki as an AJAX Mashup Framework
POWER PANELS:
The Business Value
of RIAs
What Lies Beyond AJAX?
KEYNOTES:
Douglas Crockford
Can We Fix the Web?
Anthony Franco
2008: The Year of the RIA
Click For 2007 Event Webcasts
SYS-CON.TV
TOP THREE LINKS YOU MUST CLICK ON


New Device Development Features in Visual Studio 2008
Visual Studio 2008 will migrate them to work on Windows Mobile 5.0 Smartphone using the .NET CF 2.0 runtime

Digg This!

Page 2 of 3   « previous page   next page »

And I want to underscore that almost anything you could for device development in Visual Studio 2005 you can continue to do in Visual Studio 2008.

Unit Testing for Device Developers
Let's start with the one of the most significant enhancements that we added to Visual Studio 2008 - the ability to write unit tests for your VB and C# device applications. While keeping device developers' unique needs in mind, we also kept parity with how this feature works on the desktop and Web so you can simply translate what you learned around writing unit testing for devices. Of course there are subtle differences that we had to allow for but you'll clearly see familiar dialogs and experiences when creating and running unit testing for devices such as integrating test results with back-end systems like Team Foundation Server.

To demonstrate writing a simple unit test for a device class library that you created, here's what you'd have to do (See Figure 1). Let's say you have a class library written in C# that has a method that returns the bigger of the two numbers passed to it. You want to write a unit test for it and make sure you don't goof up on the logic. So once you're in that project, right-click anywhere in the editor and select "Create a new Unit Test."

If you noticed that there's a flaw in the code trust me that's intentional. I'll be using that to highlight how your unit test will help you catch these kinds of mistakes. So please ignore that for the moment and assume that this code works as you expected.

Now, once you've clicked on create unit test, the next dialog lets you pick the methods for which you want to create unit tests (See Figure 2.)

For now we'll stick with the default and click OK and provide a project Name. This will create and add a Test Project to our solution and in the process Generate the Test Methods, add references as needed, ensure that Test Configuration Files are created and then you're ready to write your unit tests and execute them.

You'll find in your test project a Method called FindBigTest() that has a stub for the unit test for our simple method and looks like this:

TestMethod()]
public void FindBigTest()
{
      Class1 target = new Class1(); // TODO: Initialize to an appropriate value
      int Number1 = 0; // TODO: Initialize to an appropriate value
      int Number2 = 0; // TODO: Initialize to an appropriate value
      int expected = 0; // TODO: Initialize to an appropriate value
      int actual;
      actual = target.FindBig(Number1, Number2);
      Assert.AreEqual(expected, actual);
      Assert.Inconclusive("Verify the correctness of this test method.");
}

Let's modify this code to add the appropriate values for Number1, Number2, and the expected Values. For example, if Number1 is 5 and Number2 is 4 then the return value should be 5. We'll also remove the Assert.Inconclusive line and once our edits are done, right-click and select "Run Tests" from the menu. If prompted you can then select either a real device or an emulator to run your unit test on.

One tip: Make sure you have .NET Compact Framework 2.0 (or higher) on the device or emulator on which unit tests are going to execute because the unit test project won't deploy .NET Compact Framework and expects it to be there already. One easy way to do this is by deploying a simple VB or C# project to the device before you run your unit tests.

[TestMethod()] //After the changes are made
public void FindBigTest()
{
    Class1 target = new Class1();
      int Number1 = 5;
      int Number2 = 4;
      int expected = 5;
      int actual;
      actual = target.FindBig(Number1, Number2);
      Assert.AreEqual(expected, actual);
}

Once you select Run tests, you'll notice that the emulator shows up (if running on the emulator) and Visual Studio starts to deploy the Unit Test Harness, your class library, and the test code to it. You'll also see that the Test Results Window shows up with the executing test reflecting the state of Pending. Give it a few seconds to execute and you should see something similar to Figure 3.

That clearly worked when Number1 was greater than Number2. Now let's test the other condition as well and make sure that if Number2 in bigger then our code works also as expected and returns that. So in our test we can swap Number1=4 and Number2=5 and execute the test again. Now it gets interesting. Your test just failed (see Figure 4).

No, don't panic. Remember the flaw in the code before? We were returning Number1 in both cases. While we did it intentionally to highlight how unit testing work, these are the kinds of scenarios that having unit tests can save you hours of debugging. So to ensure that this example works, simply fix the code in the class to return Number2 where applicable, rerun your unit test, and it will certainly come back as Passed.


Page 2 of 3   « previous page   next page »

About Amit Chopra
Amit Chopra is the release program manager for the Visual Studio for Devices team. He also manages the sustained engineering efforts for eMbedded Visual C++ 4.0 and Visual Studio 2003. He can be contacted at achopra@microsoft.com.

LATEST JAVA STORIES & POSTS
Saving Your Investment: Transforming J2EE applications into Web 2.0 using GWT
The pressure is on to keep pace with Web 2.0 entrants into the marketplace. Rewriting is expensive; adding AJAX widgets results in a complex, unmaintainable application. Both require you to hire scarce JavaScript developers. Google Web Toolkit -- the SDK that allows you to write
WSRP Really Works! - Part 2
A standard from OASIS called Web Services for Remote Portlets (WSRP) is used so portlets can be decoupled from a portal. In part one (JDJ, Volume. 13, issue 3) of this article, we introduced the relevant standards and specifications and then demonstrated WSRP's capabilities by co
Adobe's Kevin Lynch and Microsoft's Scott Guthrie to Keynote AJAX World RIA Conference & Expo
Two of the biggest launches in Rich Internet Application history took place in 2007/2008 when Adobe launched AIR 1.0 in February '08 and Microsoft launched Silverlight (September '07). At the 6th International AJAXWorld RIA Conference & Expo in October SYS-CON Events is delighted
Sun Expects Q4 Earnings Above Estimates
On Tuesday evening Sun issued a fourth-quarter guidance range largely above analysts' estimates. The company pre-announced that revenue for its fiscal fourth quarter ended June was $3.725 billion to $3.8 billion, with gross margin in the 44-45% range. Sun expects non-GAAP profits
Virtualization Conference Keynote Webcast Live on SYS-CON.TV
Brian Stevens, the Chief Technology Officer and Vice President of Engineering of Red Hat, delivered his Virtualization Keynote 'The Future of the Virtual Enterprise' at SYS-CON's Virtualization Conference & Expo 2007 West in San Francisco. 'Virtualization is the hottest subject
The Beauty of JavaScript
JavaScript is one of the most interesting and misunderstood programming languages in common use today. Most developers will go their entire careers without realizing its full potential. It's not often that you get a language that supports the feature set that JavaScript does, whi
SUBSCRIBE TO THE WORLD'S MOST POWERFUL NEWSLETTERS
SUBSCRIBE TO OUR RSS FEEDS & GET YOUR SYS-CON NEWS LIVE!
Click to Add our RSS Feeds to the Service of Your Choice:
Google Reader or Homepage Add to My Yahoo! Subscribe with Bloglines Subscribe in NewsGator Online
myFeedster Add to My AOL Subscribe in Rojo Add 'Hugg' to Newsburst from CNET News.com Kinja Digest View Additional SYS-CON Feeds
Publish Your Article! Please send it to editorial(at)sys-con.com!

Advertise on this site! Contact advertising(at)sys-con.com! 201 802-3021

SYS-CON FEATURED WHITEPAPERS

SPONSORED BY INFRAGISTICS
SOA in a JVM: OSGi Service Platform - A Dynamic Component System for Java
There are many forces that influence technological evolution. After a decade of building enterprise
AJAX and Enterprise RIA Tools - JSF, Flex, and JavaFX
2008 is going to be an important year for Rich Internet Applications. Most organizations are deliver
Final Voting Phase on OpenAjax Browser Wishlist
The OpenAjax Alliance is developing an Ajax industry wishlist for future browsers, using a dedicated
AJAX World RIA Conference News - Netflix UI Guru To Present on Crafting Rich Web Interfaces
In every field of design one of the first things students do is learn from the work of others. They
Infragistics Releases CTP UI Components for Microsoft Silverlight Beta 2
Infragistics announced the availability of two Community Technology Preview (CTP) User Interface (UI
Yahoo User Interface 2.5.2 Released
The YUI development team has released version 2.5.2; you can download the new release from SourceFor
ADS BY GOOGLE
BREAKING JAVA NEWS
Domark International, Inc. Completes Its Acquisition of Javaco, Inc.
Domark International, Inc. (OTCBB:DOMK) announced today that it has completed its acqui