Hot answers tagged

144

No. The simplest example I've seen is: branch A cleans unused imports in a file. Branch B adds code that actually uses some of the unused imports. Git merges automatically since the lines that were changed were not the same. Code can no longer compile and unit tests can not run.


114

No. As a counter example, consider branch A adds a unit test that uses reflection to check for a misspelling in an enum. And branch B adds a misspelling. Both pass because a misspelling doesn’t fail a build, in A the test doesn’t fail because everything is spelled right, and in B there isn’t a test to check it. There won’t be any merge conflicts because the ...


35

Here is an example which neither does require changes to the existing tests itself, nor reflection, nor a failing build, for not giving the wrong impression such cases can only happen under artificial circumstances. Assume the codebase contains a private function f which is currently not called anywhere (maybe it was in the past, but noone has deleted it). ...


10

Approaching this from a different angle, there's a simple process to ensure that the tests continue passing after merging both branches: a branch must pass CI after being applied to the current target branch before being merged. So when branch A merges, the goalpost for the other branches move to "main branch with A applied to it." To expedite this,...


8

If two individual branches pass unit tests, once they're merged, is the result also guaranteed to pass unit tests? Taking the question at face value, it's very simple to create an example where one branch only tests part of its codebase and has a bug in the untested part. Its unit tests pass, but there is a bug in the code. Therefore, any test from the ...


6

I do not care about the nested classes. I care about being forced to look at things that don’t matter. Tell me one story at a time. The whole point of not putting all the code in one file is that the stuff I have to think about now is in one place and stuff I don’t need to see now hides in some other file. Oh sure, you can mash it all into one file and ...


3

No. The solution to your problem is to take advantage of the fact that git is distributed and run your automated tests against the product of the desired merge locally (ideally on a CI runner) before pushing that merge commit to the shared repository (ideally performed by that CI runner). Why this isn't the default paradigm for this sort of thing is ...


2

As the other answer stated, no, passing tests on 2 non-conflicting branches are not enought to say there won't be failures after merging them both. You have plenty of examples. Let me focus on the second part of the question, the proposed flow, how it may fail and how it might be approached: When a pull request is made, run the unit tests to catch anything ...


1

It depends There is no strict rule, so choose what suits you best. In doubt, test : If the effort is not that big and reassure you then go for it and add the combinated test Rely on End to End tests : If each case is well tested independently, and the combination should work (e.g. by design) you can rely on E2E tests to cover the combined tests.


1

Let's look on how to prevent the problem. As mentioned in the question, CI (typically) reruns after every commit to the default branch, including merges. Some of the answers already explain how things can break. Some other answers suggest a dev branch and fast-forward the main branch only when the CI is stable on dev. But this would require additional manual ...


1

Another problem scenario is that the original program performed a safety check in both a private function, and in its calling code. Branch A removes the check from the function, and branch B removes it from the calling code. Both branches will perform the safety check once, would for most purposes be an improvement over calling it twice, but merging the ...


1

Interesting question, I gave it some thought and came up with the following situation in which 2 branches which are independently correct, result in a merge which breaks the build. Suppose in the 2 branches a function/procedure with same name and signature is added to a class. However this is done in different locations or even different files. The resulting ...


1

[is it] appropriate to draw a data flow graph that flows from initiation of variables to constructor and method. I'd say "No" for two reasons.. "data flow graph" seems to have a pretty specific meaning, which i assume you are using too. You should show the dependencies of each function or step, which would 'reverse' your flow ie. ...


1

Rigorous software testing is not common in physical sciences. This issue caused somewhat of an existential crisis in the scientific computing community starting in the 90's about how reproducible a study can be if the methods are not thoroughly vetted. Most of the effort on addressing this has gone into standards for journals to at least require disclosure ...


Only top voted, non community-wiki answers of a minimum length are eligible