Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is there a way to run tests on a git branch while working on another one?

Tags:

git

tdd

I have a large tests suite, that needs to be run before I push my changes back to the repo used by CI. Ideally I would like to use the following workflow:

  • Create branch to develop feature or correct bug;
  • Develop the feature in this branch using TDD, but running only the most obviously related tests;
  • After finished developing, run the whole test suite;
  • While I'm running the whole test suite (20 minutes), I would like to begin another feature in another branch.

If I do a git checkout, my whole working copy is changed to that branch, so I can't run my tests. Maybe I should use 2 working copies, but I would prefer a more elegant solution.

edit: typo

like image 838
JoaoHornburg Avatar asked Jun 17 '11 14:06

JoaoHornburg


People also ask

Can you work on two branches at the same time git?

You can have many branches in your repository, but only one of these will be "checked out" as the working-tree so that you can work on it and make changes. git worktree adds the concept of additional working trees. This means you can have two (or more) branches checked-out at once.


1 Answers

You will have to make a second working copy for this; Consider that your next feature to implement may not be a new branch but instead uses an existing branch or a branch based on a different branch (anything that means you would be checking out code that reverts your last feature implementation during the test run).

You could make a script to handle all of it -- perhaps you finish development of the current feature, then run the "buildandtesteverything {featurebranchname}" script. Script will move up to the directory that contains the root of your git repository, clones the repository into a temporary folder (checking out the named branch), and then executes your tests and cleans up after itself.

like image 174
Chris Shaffer Avatar answered Nov 15 '22 18:11

Chris Shaffer