Tag: Primer

About Bash

Bash is the GNU Project’s shell. Bash is the Bourne Again SHell. Bash is an sh-compatible shell that incorporates useful features from the Korn shell (ksh) and C shell (csh). It is intended to conform to the IEEE POSIX P1003.2/ISO 9945.2 Shell and Tools standard. It offers functional improvements over sh for both programming and interactive use. In addition, most sh scripts can be run by Bash without modification.https://www.gnu.org/software/bash/

Running Bash on Mac OSX

For this primer we will be using a text editor to write the .sh file and executing them via Terminal. In Finder, search for “Terminal” and select Terminal from Applications.

Running .sh Files via Terminal

The first line contains a shebang #! followed by the path to the shell, in this case bash – this acts as an interpreter directive and ensures that the script is executed under the correct shell.http://ss64.com/osx/syntax-shellscript.html

Open Terminal

Enter chmod u+x {scriptName}.sh and press enter

chmod changes the access permissions

u = User Permission

x = Execute

Enter ./{scriptName}.sh and press enter

dot slash (./) is used in Linux and Unix to execute a compile program in the current directory

You can setup a PATH so that you do not have to enter the dot slash every time

Hello World!

echo
Display message on screen, writes each given STRING to standard output, with a space between each and a newline after the last one.http://ss64.com/bash/echo.html

Open Terminal

Type echo 'Hello World!'

"Hello World!"

Variables

You can use variables as in any programming language. There are no data types. A variable in bash can contain a number, a character, a string of characters.
You have no need to declare a variable, just assigning a value to its reference will create it.http://tldp.org/HOWTO/Bash-Prog-Intro-HOWTO-5.html

Functions

Like “real” programming languages, Bash has functions, though in a somewhat limited implementation. A function is a subroutine, a code block that implements a set of operations, a “black box” that performs a specified task. Wherever there is repetitive code, when a task repeats with only slight variations in procedure, then consider using a function.http://tldp.org/LDP/abs/html/functions.html

Passing Variables to Functions

Previously, message was accessible because its scope was Global. You can pass variables and values to functions by appending those values to the function call. Also, your function must expect a value. In this example, we pass a string into the function that is assigned a numerical value (the first argument is $1). Use $# to assign the passed in argument to a local variable.

Error Handling

Bash doesn’t have Try…Catch like PowerShell. So, I have tried to frame out how that could be addressed manually. In the example below I pass commands as strings to a Try() function and if that command returns an error it will be caught and addressed in a Catch() function.

About Automated Software Testing

In software testing, test automation is the use of special software (separate from the software being tested) to control the execution of tests and the comparison of actual outcomes with predicted outcomes. Test automation can automate some repetitive but necessary tasks in a formalized testing process already in place, or add additional testing that would be difficult to perform manually.http://en.wikipedia.org/wiki/Test_automation

Picking the Right Tools for the Job

There is no one-size-fits-all solution. You will need to take into consideration:

Example: I wrote a script that copies the latest build from the build machine to each test environment and installed that latest build. The scripts also sent out an email when it successfully ran a warm-up test, telling QA the build was ready to be tested.

Recommendations

For scripting, I prefer PowerShell. It is fully supported by Microsoft and comes pre-installed on most Windows OS deployments.

For testing, I prefer Test Studio. It has quarterly releases by Telerik and hits all the right notes in what I consider a good tool.

Why Telerik Test Studio?

Usability

Layout is clear and familiar (follows MS Office lead)

Ease of Use

Beginners can record-and-click to create new tests. They can also edit tests, like modify the find logic of an html element, rather easily.

Advanced users can write custom code in VB or C#.

One environment

In Selenium you need separate programs to create, edit, and playback test.

In Test Manager you need to have Visual Studio Pro (or higher) to convert test cases from recorded actions to automated tests.

Compatibility

Browsers: Internet Explorer, Chrome, Firefox, Safari

Application Platforms: Silverlight and WPF

Productivity

Tests and created and modified quickly.

Comments

Each Test and Test List has a description. Each Test Step can be commented or have its description altered.

Was there a close second?

Microsoft Test Manager is evolving with each iteration and could come to surpass HP’s Quality Center for enterprise solutions. It could overtake Telerik if it lets the Test Professional edition write automated tests and those tests are in a separate solution for the application.

Strengths

Test plans and test cases are saved as part of the project

Manual testing has great features

Sidebar to step through test cases and mark as pass or fail

Take photos or videos of testing

Attach bugs in TFS

Weaknesses

Fragmented IDE requirements

Must have Test Professional to make tests but must have Visual Studio Professional (or higher) to convert tests to automation

Limited browser support

High initial cost

Best Practices

Try not to rely on existing data

Your data will typically be wiped when a new build is deployed or when a vm is snapshot reverted

Check for dependencies

Do not fail an automated test that deletes a record if the record cannot be found.

This is a setup issue. The functionality is not being tested, only it’s error handling.

One failed test should not invalidate the rest of testing

Because the homepage test fails does not mean you can’t test other pages

About Software Testing

Software testing is an investigation conducted to provide stakeholders with information about the quality of the product or service under test. Software testing can also provide an objective, independent view of the software to allow the business to appreciate and understand the risks of software implementation. Test techniques include, but are not limited to the process of executing a program or application with the intent of finding software bugs (errors or other defects).http://en.wikipedia.org/wiki/Software_testing

Test Environment

The environment in which you will test is likely predetermined by the QA team, Development team, or the Infrastructure team. Use of virtual machines (vm) is standard practice. Virtual machines allow you to pre-configure an environment (OS/Software combo) and save as a snapshot. A tester can fire up the vm and perform his/her testing and revert the vm when finished. Use of a VM is preferred over your workstation, because you want to limit potential risk factors. VMs should contain just your software (and any dependencies) and the OS. You may also want to include some testing tools, like Fiddler.

Smoke Test

Verify that the current build is worth the effort of a full test. Sometimes a build breaks so bad that you cannot perform simple tasks. These should be done first in each environment and requires co-ordination in large teams. A build could be broken in one particular OS/Software combination and the fix will require a re-factoring. In this case you wouldn’t want to continue testing in the other environments as it will change soon.

Concurrent Testing

Concurrent Testing is the process of running automated tests while manual testers do exploratory testing. Any company that uses test automation, will have some sort of concurrent testing. No one should rely solely on automated tests.

Playback

Clear the contents of cell A1

Click the Macros button on the View tab

Select View Macros

Select your macro from the list

Click the Run button

"Hello World!"

Variables

You often have to store values when you perform calculations with Visual Basic. For example, you might want to calculate several values, compare them, and perform different operations on them, depending on the result of the comparison. You have to retain the values if you want to compare them.http://msdn.microsoft.com/en-us/library/cd6hcy37.aspx

Functions

All executable code must be inside a procedure. Each procedure, in turn, is declared within a class, a structure, or a module that is referred to as the containing class, structure, or module.
To return a value to the calling code, use a Function procedure; otherwise, use a Sub procedure.http://msdn.microsoft.com/en-us/library/sect4ck6.aspx

Error Handling

In Microsoft Excel, you can use the On Error statement in a Microsoft Visual Basic for Applications macro (Sub procedure) to trap errors and direct procedure flow to the error-handling statements in a procedure. By using error handling, you make your macros and your application easier to use by intercepting run-time errors before the user sees them.http://support.microsoft.com/kb/141571

Sub Macro1()
' Run the Error handler "ErrHandler" when an error occurs.
On Error GoTo Errhandler
writeMessage ("Hello World!")
' Disable the error handler.
On Error GoTo 0
' Exit the macro so that the error handler is not executed.
Exit Sub
Errhandler:
' If an error occurs, display a message and end the macro.
MsgBox "An error has occurred. The macro will end."
End Sub
Sub writeMessage(message As String)
Range("A1").FormulaR1C1 = message
End Sub

Download C#

The fastest way to start developing applications for Windows 8.1, Windows Phone, the web or the cloud. Visual Studio Express products provide a free development environment to develop applications for the latest platforms. Since it is Visual Studio, applications created in Express can be supported in other versions of Visual Studio as your needs grow.http://www.visualstudio.com/en-us/products/visual-studio-express-vs.aspx

Starting C#

Learn how easy it is to set up Visual Studio and connect to Visual Studio Online. Once you’re set up, we’ll show you how to create and organize your backlog, share your code with your team, and configure your app for continuous builds and deployment. Choose any of the sections below to get started.http://www.visualstudio.com/get-started/overview-of-get-started-tasks-vs

Variables

The C# typing system contains the following categories: Value types, Reference types, and Pointer types.
Variables that are value types store data, and those that are reference types store references to the actual data. Reference types are also referred to as objects. Pointer types can be used only in unsafe mode.
It is possible to convert a value type to a reference type, and back again to a value type, by using boxing and unboxing. With the exception of a boxed value type, you cannot convert a reference type to a value type.
This section also introduces void.
Value types are also nullable, which means they can store an additional non-value state. For more information, see Nullable Types.http://msdn.microsoft.com/en-us/library/3ewxz6et.aspx

Functions

A method is a code block that contains a series of statements. A program causes the statements to be executed by calling the method and specifying any required method arguments. In C#, every executed instruction is performed in the context of a method. The Main method is the entry point for every C# application and it is called by the common language runtime (CLR) when the program is started.http://msdn.microsoft.com/en-us/library/ms173114.aspx

Passing Variables to Functions

Previously, message was accessible because its accessibility level is private (default). Meaning it is accessible from within the Hello class. In this example, we will pass a string value to a method as a parameter.

Further Reading

Most of this section assumes that you already know something about C# and general programming concepts. If you are a complete beginner with programming or with C#, you might want to visit the C# Developer Center, where you can find many tutorials, samples and videos to help you get started.

About T-SQL

Transact-SQL is central to using SQL Server. All applications that communicate with an instance of SQL Server do so by sending Transact-SQL statements to the server, regardless of the user interface of the application.http://msdn.microsoft.com/en-us/library/bb510741.aspx

Download T-SQL

Microsoft SQL Server 2014 Express is a free, feature-rich edition of SQL Server that is ideal for learning, developing, powering desktop, web & small server applications, and for redistribution by ISVs. The SQL Server 2014 Express release includes the full version of SQL Server 2014 Management Studio instead of SQL Server 2014 Management Studio Express.http://msdn.microsoft.com/en-us/library/dn434042.aspx

Starting T-SQL

SQL Server Management Studio is not installed by default. If Management Studio is unavailable, install it by running Setup. Management Studio is not available with SQL Server Express. Management Studio Express is available as a free download from the Microsoft Download Center, but has a different user interface than is described in this tutorial.http://msdn.microsoft.com/en-us/library/ms166996.aspx

To open SQL Server Management Studio

On the Start menu, point to All Programs, point to Microsoft SQL Server 2014, and then click SQL Server Management Studio.

In the Connect to Server dialog box, verify the default settings, and then click Connect. To connect, the Server name box must contain the name of the computer where SQL Server is installed. If the Database Engine is a named instance, the Server name box should also contain the instance name in the format <computer_name>\<instance_name>.

Hello World!

Retrieves rows from the database and enables the selection of one or many rows or columns from one or many tables in SQL Server. The full syntax of the SELECT statement is complex, but the main clauses can be summarized as:
[ WITH <common_table_expression>]
SELECT select_list [ INTO new_table ]
[ FROM table_source ] [ WHERE search_condition ]
[ GROUP BY group_by_expression ]
[ HAVING search_condition ]
[ ORDER BY order_expression [ ASC | DESC ] ]
The UNION, EXCEPT and INTERSECT operators can be used between queries to combine or compare their results into one result set.http://technet.microsoft.com/en-us/library/ms189499.aspx

Open SQL Server Management Studio

Click File, point to New, and then select Query with Current Connection

Type SELECT 'Hello World!'

Execute the script by pressing [F5]

"Hello World!"

Variables

Variables are declared in the body of a batch or procedure with the DECLARE statement and are assigned values by using either a SET or SELECT statement. Cursor variables can be declared with this statement and used with other cursor-related statements. After declaration, all variables are initialized as NULL, unless a value is provided as part of the declaration.http://msdn.microsoft.com/en-us/library/ms188927.aspx

Functions

Like functions in programming languages, SQL Server user-defined functions are routines that accept parameters, perform an action, such as a complex calculation, and return the result of that action as a value. The return value can either be a single scalar value or a result set.http://msdn.microsoft.com/en-us/library/ms191007.aspx

Attaching a Sample Database

RELEASE NOTESAbout this release
This release consolidates AdventureWorksDW databases for SQL Server 2012, 2008R2 and 2008 versions to one page. Each zip file contains an mdf database file and an ldf log file. This should make it easier to find and download AdventureWorksDW databases since all OLAP versions are on one page.http://msftdbprodsamples.codeplex.com/releases/view/93587

An AdventureWorksDW database can be installed by attaching the database, or using the CREATE DATABASE statement.To attach an AdventureWorks database

About Python

Python is an interpreted, interactive, object-oriented programming language. It incorporates modules, exceptions, dynamic typing, very high level dynamic data types, and classes. Python combines remarkable power with very clear syntax. It has interfaces to many system calls and libraries, as well as to various window systems, and is extensible in C or C++. It is also usable as an extension language for applications that need a programmable interface. Finally, Python is portable: it runs on many Unix variants, on the Mac, and on Windows 2000 and later.https://docs.python.org/3/faq/general.html#what-is-python

Click Start, point to All Programs, point to Python 3.4, and then click IDLE (Python GUI).

Hello World!

Open IDLE

Click File and then click New File

Type print('Hello World!')

Note: In Python V2 it would be print 'Hello World!'

Execute the code by pressing [F5]

"Hello World!"

Variables

The principal built-in types are numerics, sequences, mappings, classes, instances and exceptions.
Some collection classes are mutable. The methods that add, subtract, or rearrange their members in place, and don’t return a specific item, never return the collection instance itself but None.
Some operations are supported by several object types; in particular, practically all objects can be compared, tested for truth value, and converted to a string (with the repr() function or the slightly different str() function). The latter function is implicitly used when an object is written by the print() function.https://docs.python.org/3/library/stdtypes.html

Passing Variables to Functions

Previously, message was accessible because its scope was Global. You can pass variables and values to functions by appending those values to the function call. Also, your function must expect a value. In this example, we pass a string into the function that we declare as message.

Error Handling

The try statement specifies exception handlers and/or cleanup code for a group of statements.
The except clause(s) specify one or more exception handlers. When no exception occurs in the try clause, no exception handler is executed.
If finally is present, it specifies a ‘cleanup’ handler. The try clause is executed, including any except and else clauses.https://docs.python.org/3/reference/compound_stmts.html#the-try-statement

Related

About PowerShell

Windows PowerShell® is a task-based command-line shell and scripting language designed especially for system administration. Built on the .NET Framework, Windows PowerShell helps IT professionals and power users control and automate the administration of the Windows operating system and applications that run on Windows.http://technet.microsoft.com/en-us/library/bb978526.aspx

Starting PowerShell

The Windows PowerShell Integrated Scripting Environment (ISE) is a host application for Windows PowerShell. In Windows PowerShell ISE, you can run commands and write, test, and debug scripts in a single Windows-based graphic user interface with multiline editing, tab completion, syntax coloring, selective execution, context-sensitive help, and support for right-to-left languages. You can use menu items and keyboard shortcuts to perform many of the same tasks that you would perform in the Windows PowerShell console. For example, when you debug a script in the Windows PowerShell ISE, to set a line breakpoint in a script, right-click the line of code, and then click Toggle Breakpoint.http://technet.microsoft.com/en-us/library/dd315244.aspx

Do one of the following:

Click Start, point to All Programs, point to Windows PowerShell V2, and then click Windows PowerShell ISE.

In the Windows PowerShell console Cmd.exe, or in the Run box, type, powershell_ise.exe.

Variables

When you write a script, particularly a system administration script, you rarely get to hard-code in all your values ahead of time; instead, you typically need to retrieve information, store that information in a variable or two, and then display the values of those variable.http://technet.microsoft.com/en-us/library/ee692790.aspx

PowerShell is influenced by Unix shells and Perl so variables are prefixed with a $sigil.

Windows PowerShell uses a verb-noun pair for the names of cmdlets and for their derived Microsoft .NET Framework classes. For example, the Get-Command cmdlet provided by Windows PowerShell is used to retrieve all the commands that are registered in Windows PowerShell. The verb part of the name identifies the action that the cmdlet performs. The noun part of the name identifies the entity on which the action is performed.http://msdn.microsoft.com/en-us/library/ms714428(v=vs.85).aspx

Passing Variables to Functions

Previously, $message was accessible because its scope was Global. You can pass variables and values to functions by appending those values to the function call. Also, your function must expect a value. In this example, we pass a string into the function that we declare as $message.