background

Recently, I joined a startup company. I was pleasantly surprised to find that the entire testing system of the company is basically zero, which is based on the test cases of N years ago + pure hand-based testing. The iterative quality is completely unguaranteed, and every time we go online, we have to “take a chance”. In big factory many years, have never encountered such a difficult problem, each time on-line is a test.

Chat with test this matter, test small elder sister decisive reply, learn not!

Therefore intends to “test” this topic to do a thorough investigation, from theory to practice step by step, welcomes each big boss to comment and teach.

Why spend time on automated testing?

First of all, before the investigation, we should first make clear why we need to do this thing. The interface has the interface use case test, and the front-end UI test is complicated and tedious. What is the significance and value of doing this thing?

Take our current situation as an example:

Small factories, start-up companies, non-Internet enterprises, average per capita capacity, large mobility of personnel, belong to the project category, each on-site emergency customization needs More.

The code written by such a group looks like this:

A: Using scaffolding, A command line builds A project framework and writes the engineering structure.

B: THERE is a demand from the XX site. It seems to add a paragraph of “if…” here. else…

C: There is a request from BB. It seems that we need to add another if… else…

A year later, a dozen if… else… Some even seem to never walk in

D: The seniors are gone, now it seems that the bug is the problem of this code, but how to get into each branch?

C: Don’t ask me, I don’t know. else…

D delete this condition, a site for the update program after the scene died.

D fell out of thin air a big accident, the conversion is also a problem, leaving a few new if… else… “And left.

So what does this have to do with automated testing?

If there are automated tests, delete the if… else… “, the test results will give you a big Fail, reminding you that you can optimize the code with proper refactoring, rather than deleting it with one click.

Using a script automatically run test cases, usually only takes a few seconds can give accurate feedback, at the same time also can listen for the code change, automatically perform project changed code in the corresponding test cases, can greatly improve the efficiency of our development, also tests only need in the protection of the user through the complete, do some mainstream into testing and validation of the change of function.

Developers no longer have to worry about one or two lines of code changing, causing unpredictable problems, and no need to worry about accepting a “bad” project.

And the enterprise, also need not excessive fear personnel flow.

The benefit of test automation is timely feedback, which can greatly improve front-end development efficiency.

Benefits of test automation = Number of iterations × cost of full manual execution − Cost of first automation − Number of maintenance × maintenance cost

What is an automated test?

As every engineer knows, testing is both our nightmare and our salvation.

The official explanation is,

Testing is a way of verifying, manually or otherwise, that software that has already been developed meets engineering expectations and potentially causes problems such as user/developer losses.

For a long time, we wrote front-end code that was either developed for manual self-testing or was manually tested by dedicated testers to ensure the accuracy of predictable operations.

Later, with the improvement of testing capability and the frequent discovery of non-operational problems in the field, interface testing, also known as unit testing, was introduced, and some pressure testing was added to ensure the stability of the system.

Manual testing + unit testing is certainly fine, but as the project becomes more and more functional, full manual testing becomes a difficult task, and with automated testing tools, problems can be quickly and efficiently identified.

An automated test is actually running a piece of test code to verify that the object code meets some expectation.

Hierarchy and classification of tests

Automated testing is divided into several levels. The pyramid model shown in the figure may be seen by many people. For each level, there are many mature open source frameworks:

  • Unit testing

Unit tests are the easiest to implement: utility libraries shared by multiple components in your code, child components shared by multiple components, and so on.

In general, there must be unit tests in the common functions/components to ensure that the code works. Unit tests should also be the most numerous and covered in the project.

A function/component that can be unit-tested must be low-coupled, which ensures the quality of our code to some extent.

Common test frameworks include unittest, Junit, TestNG, Jest, Mocha, Jasmine…..

  • Integration testing

Integration testing is usually applied to functions/components that are highly coupled, functions/components that are twice encapsulated, functions/components that are composed of multiple functions/components, etc.

The purpose of integration testing is to test whether unit-tested modules work together. The combined code as a whole is exposed to the external interface and tested to see if the combined code works as expected.

Integration tests are security tests that can greatly enhance the confidence of developers. The integration test cases are designed properly and the tests are passed to greatly ensure that the product meets expectations.

Common test frameworks are unittest+python+requests, RobertFramework, Jmeter….

  • UI test

UI tests are only tests of the front end, they are not in the real back end environment, they are just running the front end in the real environment, the back end and the data should be Mock.

UI testing is very poorly automated at the moment, so that’s one of the areas I want to focus on.

This topic will study and organize various testing frameworks, and select the most suitable framework to be used in the project through the consideration of each indicator, and encapsulate and transform the parts that are not satisfied.