Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What git branch should I commit unit tests to?

I'm currently following the ever-popular git workflow described here.

One thing it doesn't discuss is how to handle unit testing. Let's say I write some code and commit to develop. I want to write a test for it, but I don't want it in my develop history, I'd like to keep the tests separate so that when I look at git log I only see changes to the main code. However, if I commit the test to a separate test branch, I'll have to merge develop/test back and forth constantly, resulting in a ridiculous amount of merge commit clutter.

How do you manage unit testing in a git repository?

like image 252
Ayrton Massey Avatar asked Jul 07 '15 17:07

Ayrton Massey


People also ask

Where should the unit tests reside in the repository in Devops?

Unit testing often finds its place just after the build stage of the delivery pipeline. Developers commit their code and push it to a code repository.

What are the three types of branching in Git?

The two primary branches in Git flow are main and develop. There are three types of supporting branches with different intended purposes: feature, release, and hotfix.

Should I push tests to GitHub?

You definitely should put your tests into the repository. Tests are in my opinion part of the code and can help others immensely to understand it (if well written). Besides, they can help others when changing or contributing to your codebase.

How do I commit a test file to a Git project?

Create a pre-commit git hook to execute your tests. In an example, Python projects use pytest to execute tests. Now each time you issue commit command to git it will run the script. The commit will fail when pytest fails. Effectively you will not be able to commit to git code which is not tested.

What are branches in Git?

Multiple people create separate branches to work on their code and merge their changes into the main branch. Branches are meant to be temporary and should be deleted when work is completed. Branch names can be anything you’d like.

Can I create a branch from a previous commit in Git?

You can create a branch from a previous commit on an existing branch. Remember, a commit is just a snapshot in time of the files in a repository. You create a branch from a commit if you want to work on a specific snapshot of the files. Before creating the branch, you need the SHA-1 identifier of the commit.

How to commit code locally using Git push?

You will be able to commit code locally, but when you run git push, before git executes the command, it will execute the pre-push script. If the script finishes with error, the push command will be aborted. You can run the git commit or git push command. The hook will be executed before the actual command runs.


Video Answer


1 Answers

Unit tests are part of your source tree: They evolve as your code evolves, and feature branches have their own unit tests that evolve as the features evolve. There's no reason to keep them in a separate branch.

Note that git log accepts a path parameter, so if you want to avoid seeing test-only log entries, you can do the filtering at that point. I typically keep my src and testsrc source folders separate and adjacent, so I can see changes to one or the other easily just by specifying git log src or git log testsrc.

like image 82
Jeff Bowman Avatar answered Oct 08 '22 15:10

Jeff Bowman