300 likes | 492 Views
Advanced ASP .NET. Testing and Deployment David Grey, University of Hull. Introduction. Visual Studio has great support for building ASP .NET web applications Real web application development involves more than just copying the files created in Visual Studio
E N D
Advanced ASP .NET Testing and Deployment David Grey, University of Hull
Introduction • Visual Studio has great support for building ASP .NET web applications • Real web application development involves more than just copying the files created in Visual Studio • In this session we look at the issue of deploying and testing ASP .NET applications
Demo • The sample application • Self-contained slice of large web application • Interacts with web services • Retrieves data from database • User authentication
Real-World Web Deployment Production Database Test Database Web Application Production Web Server Staging Web Server Developer’sWorkstation Web Application Web Application Web Application
Configuring Deployment • Different configurations are required for development, testing and production • Development • Local test web server, debugging, (local)test data, full source, editing support, local services • Testing • IIS, debugging?, source?, shared test data, distributed services • Production • No debugging, fully optimised, production data stores, enhanced security
Web Deployment Projects • Add-on for Visual Studio which offers • Pre-compilation of ASP .NET sites • Flexible options for generating compiled assemblies from a Web project • Control over assembly naming, versioning and signing • Ability to exclude, add, and transform files and directories during builds • Modification of settings in the Web.config file • Generation of MSI installer setup • Tied to configuration settings of Web project • Really useful in building real-world web applications
Output Options • Source files pre-compiled into assemblies • One assembly per page • Single assembly for all pages • Compiled site can be • Updateable • Page markup shipped with site • Useful for intra-organisation sites which may need modification after deployment • Non-updateable • Page markup compiled into assembly(s) • Useful for ‘boxed’ applications where end-user should not be able to modify site
Creating Deployment Configurations • Arbitrary sections of Web.config file can be modified for each build configuration • External file contains specific replacement for each build • WDP options specify which configuration sections should be replaced • Useful for • Changing connections strings (e.g. database) • Disabling debugging for production release
Demo • Creating a Web Deployment Project • Setting build options • Output format • Assembly naming, versioning and signing • Modifying configuration settings • Creating an installer
Deployment Wrinkles • Replacement config files show up in deployed application • Combine WDP with custom MS-Build tasks (http://waynebrantley.com/blogs/aspnetbytes/archive/2006/02/08/5.aspx#11) • Compiling sites to a single assembly and making them non-updateable can cause problems when • Minor (markup) layout errors need fixed • App must be recompiled and redeployed • Obfuscation used to protect IPR • Metadata removal/type renaming by obfuscator can cause problems in locating types when ASPX pages are removed • Using updateable pages requires code-behind types to maintain their names
Web Deployment Projects • Pros • No source or markup deployed to site allows for protection of intellectual property • Secure – site can be made non-updateable • Performance – precompilation avoids compilation overhead on initial page load • Cons • Must deploy all at once; can’t upgrade part of the application • Can’t compile applications with sub-virtual directories • Can interfere with continuous service as large sites are deployed (due to assembly swapping)
Testing • Testing is key to • Verifying web application functionality • Web unit tests • Verifying that non-functional requirements (e.g. performance, scalability) have been met • Load tests (makes use of web unit tests) • Automated testing is required • Visual Studio supports both kinds of testing against arbitrary web sites • Can be performed automatically as part of daily build cycle
Web Unit Testing • Black-box approach • Verifies expected page behaviour (i.e. output) when supplied with known input • Web Test Recorder • Create web test by interacting with web site in Internet Explorer • Recorder captures interactions to create test • Can capture timing information (think times) • Gives more accurate simulation of user behaviour • Can configure test parameters to be retrieved from a database
Demo • Recording Web tests • Executing Web tests • Using parameterised tests
Load Testing • Goal of load testing is to exercise application under conditions that are as close as possible to those the application will experience in real use before it goes live • Volume of users, traffic patterns and user behaviour, mix of browsers, network characteristics • Stress-testing of application by simulating multiple users accessing site • Thousands of simultaneous users • Users performing different actions • Load testing enables • worst case performance evaluations • investigation of application performance under different conditions • comparative evaluation of design alternatives to allow optimisation
How Load Testing Works Test Scripts TestAgent TestAgent TestAgent Application under test Test Controller
Defining the test mix • Users do a variety of things with a web application at the same time • Load testing can simulate this by using multiple web tests • Create web tests for each of the user activities • Select web tests to include in the load test scenario • Alter the mix (ratio) of tests to produce an activity mix similar to the real usage scenario
Simulating browser types • Users access your site from a range of browsers; load tests can simulate this • Out-of-box emulation support • IE 5.5, IE 6, Netscape, Pocket IE • Custom browser types can be added • Create additional browser config file in C:\Program Files\Microsoft Visual Studio 8\Common7\IDE\Templates\LoadTest\Browsers • Obtain browser settings by opening http://www.ranks.nl/tools/envtest.html in browser you wish to emulate. Copy settings to config file
Simulating connection characteristics • Users access application from a variety of different networks • LAN, Broadband, Dial-up, etc • Load testing can simulate the effect of the different network bandwidths • Allows evaluation of performance experienced by client on particular types of network
Simulating traffic patterns • VS can simulate • Fixed user load accessing the site • Not representative of real traffic but useful for worst case analysis • Load varying over time • Ramp up from initial load to a maximum load • Think times recorded in web tests can be used to make timing of simulated web requests as close as possible to real traffic
Performance Counters • Monitoring of Windows performance counters is key to understanding the performance of your application • Performance counters exist for • OS (CPU/memory/IO,etc),.NET CLR, ASP .NET, IIS, SQL Server, VS testing framework • Test framework counters are monitored by default • Counters can be monitored across local and remote machines
Test Results • Show performance counters over time in graphical or tabular form
Demo • Creating a test results repository • Creating a load test • Executing the tests • Viewing live performance data • Post-test analysis
Web Testing with AJAX • Web Test Recorder works well with standard ASP .NET applications • Cannot properly record interactions with applications that use AJAX => test failures • Download and use Fiddler2 to record tests for AJAX applications • Add the tests created by Fiddler to the test project • Run web/load tests as normal
Summary • In this session we have seen how features of Visual Studio can be used to build real world web applications • Web Deployment Projects • used to control the building of web applications for testing and production • Web and load testing • used to verify the functionality and performance of Web applications
Links and References • Web Deployment Projects add-in http://msdn2.microsoft.com/en-us/asp.net/aa336619.aspx • Using Web Deployment Projects with Visual Studio 2005 http://msdn2.microsoft.com/en-us/library/aa479568.aspx • Web Deployment Project Enhancement http://waynebrantley.com/blogs/aspnetbytes/archive/2006/02/08/5.aspx#11 • Fiddler, http://www.fiddler2.com/fiddler2/ • The Science of Web Site Load Testing http://www.cmgitalia.it/download/seminario_marzo_2004/scienze_web_site_load_testing_savoia.pdf • Web Test Authoring and Debugging Techniques http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dnvs05/html/WTAuthDebug.asp • Extending Load Testing Browser Supporthttp://blog.accentient.com/PermaLink,guid,af0c2904-bc81-49f0-8156-832c09e99527.aspx