Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

With Continuous Integration, why are tests run after committing instead of before?

While I only have a github repository that I'm pushing to (alone), I often forget to run tests, or forget to commit all relevant files, or rely on objects residing on my local machine. These result in build breaks, but they are only detected by Travis-CI after the erroneous commit. I know TeamCity has a pre-commit testing facility (which relies on the IDE in use), but my question is with regards to the current use of continuous integration as opposed to any one implementation. My question is

Why aren't changes tested on a clean build machine - such as those which Travis-CI uses for post-commit tesing - before those changes are committed?

Such a process would mean that there would never be build breaks, meaning that a fresh environment could pull any commit from the repository and be sure of its success; as such, I don't understand why CI isn't implemented using post-commit testing.

like image 619
Sean Kelleher Avatar asked Apr 19 '13 10:04

Sean Kelleher


People also ask

When should integration tests be run?

We normally do Integration testing after “Unit testing”. Once all the individual units are created and tested, we start combining those “Unit Tested” modules and start doing the integrated testing. The main function or goal of this testing is to test the interfaces between the units/modules.

What is the correct order of the continuous integration process stages?

CI and CD are often represented as a pipeline, where new code enters on one end, flows through a series of stages (build, test, staging, production), and published as a new production release to end users on the other end. Each stage of the CI/CD pipeline is a logical unit in the delivery process.

When running tests as part of a continuous integration build what type of tests would you typically run first to get the quickest feedback?

Unit tests run the fastest, because they test a very small piece of code in complete isolation from the rest of the system.

Which of the following point is to check before starting continuous integration?

Check-In Regularly − The most important practice for continuous integration to work properly is frequent check-ins to trunk or mainline of the source code repository. The check-in of code should happen at least a couple of times a day.

How does continuous integration affect testing?

Continuous integration means building your software every time a developer pushes code. This affects your testing and requires careful planning and the use of test automation. Continuous integration (CI) is the process of building a new version of your software every time you push a change.

What is continuous integration (CI)?

At a high level, continuous integration (CI) is a development practice to assist in managing and automating workflows when code changes occur in a software project. Typical uses for continuous integration environments include building the software application, deploying new changes and running automated tests.

What is continuous integration in DevOps?

Continuous Integration (CI) is a DevOps software development practice that enables the developers to merge their code changes in the central repository to run automated builds and tests. It refers to the process of automating the integration of code changes coming from several sources.

What is the best tool for continuous integration testing?

For Continuous Integration testing, open source tools like Selenium and Appium are most popular for automating tests. Additionally, tools like CrossBrowserTesting can also be used to execute test automation and create an environment for continuous testing in the cloud.


2 Answers

I preface my answer with the details that I am running on GitHub and Jenkins.

Why should a developer have to run all tests locally before committing. Especially in the Git paradigm that is not a requirement. What if, for instance, it takes 15-30 minutes to run all of the tests. Do you really want your developers or you personally sitting around waiting for the tests to run locally before your commit and push your changes?

Our process usually goes like this:

  1. Make changes in local branch.
  2. Run any new tests that you have created.
  3. Commit changes to local branch.
  4. Push local changes remotely to GitHub and create pull request.
  5. Have build process pick up changes and run unit tests.
  6. If tests fail, then fix them in local branch and push them locally.
  7. Get changes code reviewed in pull request.
  8. After approval and all checks have passed, push to master.
  9. Rerun all unit tests.
  10. Push artifact to repository.
  11. Push changes to an environment (ie DEV, QA) and run any integration/functional tests that rely on a full environment.
    • If you have a cloud then you can push your changes to a new node and only after all environment tests pass reroute the VIP to the new node(s)
  12. Repeat 11 until you have pushed through all pre-prod environments.
  13. If you are practicing continuous deployment then push your changes all the way to PROD if all testing, checks, etc pass.

My point is that it is not a good use of a developers time to run tests locally impeding their progress when you can off-load that work onto a Continuous Integration server and be notified of issues that you need to fix later. Also, some tests simply can't be run until you commit them and deploy the artifact to an environment. If an environment is broken because you don't have a cloud and maybe you only have one server, then fix it locally and push the changes quickly to stabilize the environment.

You can run tests locally if you have to, but this should not be the norm.

As to the multiple developer issue, open source projects have been dealing with that for a long time now. They use forks in GitHub to allow contributors the chance to suggest new fixes and functionality, but this is not really that different from a developer on the team creating a local branch, pushing it remotely, and getting team buy-in via code review before pushing. If someone pushes changes that break your changes then you try to fix them yourself first and then ask for their help. You should be following the principle of "merging early and often" as well as merging in updates from master to your branch periodically.

like image 117
gaoagong Avatar answered Nov 08 '22 22:11

gaoagong


The assumption that if you write code and it compiles and tests are passed locally, no builds could be broken is wrong. It is only so, if you are the only developer working on that code. But let's say I change the interface you are using, my code will compile and pass tests as long as I don't get your updated code That uses my interface. Your code will compile and pass tests as long as you don't get my update in the interface. And when we both check in our code, the build machine explodes...

So CI is a process which basically say: put your changes in as soon as possible and test them in the CI server (it should be of course compiled and tested locally first). If all developers follow those rules, the build will still break, but we will know about it sooner rather than later.

like image 41
omer schleifer Avatar answered Nov 08 '22 22:11

omer schleifer