1

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.

James
  • 1,943
  • 2
  • 16
  • 29
  • 1
    it sounds like most of the business logic is on the front end but you mention unit tests as a c# thing. there are plenty of javascript test frameworks that may better suit your needs – aw04 Aug 30 '16 at 16:00
  • @aw04 yes, you are probably right and my knowledge of the automated testing is very low, so I am looking to understand it better. From what I had read so far, it seemed to focus a lot on C# type logic with methods having inputs / outputs, maybe I need to look more into the javascript test frameworks, I want to see what people are using and what the best stuff is to use – James Aug 30 '16 at 16:09
  • 1
    What javascript frameworks are you using? angularJS provides a very clean pattern for javascript unit tests and also an outstanding tool for full e2e testing in protractor. You can also use protractor without angularJS but keep in mind that e2e testing is not necessarily meant to fully cover all code in your app. Whatever you are doing in javascript, the key is to follow the same testability patterns as you would otherwise... DI, SRP, etc. – stephen.vakil Aug 30 '16 at 16:17
  • @stephen.vakil We are not using a javascript framework. We are writing mainly using the jQuery library – James Aug 30 '16 at 16:20
  • Are you not using Web API and/or MVC on the back end? If so, your controllers will be highly testable if you write them properly. – stephen.vakil Aug 30 '16 at 16:24
  • @stephen.vakil nope, not using those – James Aug 30 '16 at 16:29
  • Still hard to answer without getting a real picture of your architecture, what you've done to separate concerns in your app, what you've done to achieve isolation for testing, etc. From what you are saying so far, it seems like you chose a very difficult to automatically test architecture and now want to slap on tests afterwards. That's quite difficult compared to designing your architecture with testability in mind. – stephen.vakil Aug 30 '16 at 16:54
  • @stephen.vakil I agree completely with what you said and that's probably the best way to define what I am trying to do at the moment unfortunately. We started off with a very small team so spending time testing was less important than getting results and shipping the product. Now that we're stabilising the situation, I want to add a level of testing to the system which will inevitably be difficult. – James Aug 30 '16 at 17:09
  • Well, I guess two places to start would be https://msdn.microsoft.com/en-us/library/jj851200(v=vs.103).aspx (SQL Server unit testing) and http://stackoverflow.com/questions/4662641/how-do-i-verify-jquery-ajax-events-with-jasmine (using Jasmine to test your javascript & ajax) – stephen.vakil Aug 30 '16 at 17:17
  • be prepared to do some refactoring if you've already written the code, also mocha/chai is really good for js – aw04 Aug 30 '16 at 17:20

1 Answers1

1

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!

Community
  • 1
  • 1
Macilquham
  • 239
  • 1
  • 9