James
James

Reputation: 2033

Automated testing in web applications

We are developing a very large web application using C# and JavaScript. The majority of our calls in the code are handled with JavaScript on the front-end and the only real back-end work is the SQL server which retrieves the relevant dataset and returns it as a JSON object which is then handled once again with JavaScript.

We are currently doing all testing manually with our testers who verify the page functionality against the design specifications to make sure the software is working as expected.

I would love to be able to add some automated testing to the application. I've looked into Unit Testing and it seems that it works a lot better if you have a lot of C# methods with inputs and outputs which are easy to trace and verify that they are working.

What are the standard methods in use in the industry which we can use to verify that the whole application (or at least a majority of it) is working properly?

The sort of things I want to check are:

  1. We have an input page which lets you create a user. This input page should update, let's say, 5 tables in the database. I am adding 10 different pages which allow me to create users in the application, how can I verify that all of those pages are inserting correctly and working properly?

  2. I have a page where I can click a button which inserts a row into the database. How can I check that it's outputting correctly in all the different places it should output?

Off the top of my head, I cannot think of all the different cases I need to check but there are a huge number of them. As far as I have understood, any visual errors can only be tested by users who are manually testing.

I am looking for some feedback on what the best methods are and also how they can be applied to our type of application.

Upvotes: 1

Views: 1149

Answers (1)

Macilquham
Macilquham

Reputation: 282

Adding any tests (unit, integration, UI etc) into an existing application that has never been built with testing in mind is always a challenge but this is the approach I would look to take.

First talk to the testers and determine the top 5 areas of the application that take the longest to test and use these as the basis of where you should start adding tests.

I am assuming you have no or few tests, if this is the case I would suggest adding automated UI tests first, we use selenium and specflow. Generally these would be the last tests you write because they are the most brittle and slowest (http://martinfowler.com/bliki/TestPyramid.html).

The reason I suggest doing these first is when you look at adding unit/integration tests into your solution you are likely going to need to refactor code, refactoring code with zero unit tests will likely lead to defects, the automated tests will give you a level of confidence you haven't introduced regression as part of your refactoring.

I would then add unit and integration tests at your C# service layer, you mention a create user function updates 5 tables, not 100% knowing how your system is architected, you could test this with an integration test that invokes "CreateUser" if this call was to return the id of the newly created user you could then invoke "GetUser" with the id validating the returned entity is as expected that fact that user is augmented across 5 tables is hidden and irrelevant to the test.

Unless your company has great javascript practices purely using jquery as you UI framework will be a challenge to test (I have seen and been the cause of a number of messy jquery javascript projects). If you are serious about wanting to test I would consider looking at using a javascript framework, there are a large number for you to look evaluate. That aside there are a large number of unit testing frameworks for javascript.

In summary in an ideal world this would be my test stratergy for a SPA app (which sounds like what you have).

End to End UI Tests

  • These test the entire flow of the application (seleniuim)

Javascript

Service Layer (Web API/WCF or similar)

  • Unit tests - testing small pieces of functionality

  • Integration tests - testing across boundaries e.g. Validating input actually gets saved in database.

Things to consider

  • As aforementioned it is hard introducing testing into an existing application, you will likely need to sell the effort to the wider team, but it is very much worth it. Once you have a comprehensive test suite in place you have many advantages, faster release cadence, less defects, more time spent delivering new features, faster to fail etc etc

Good luck!

Upvotes: 1

Related Questions