0

I have a project that helps teams with their work flow in git. It has some functionality to enforce naming conventions and keep branches in sync with the remote (i.e. prevents branches from diverging as a result of the user not pulling before starting development)

The project is developed around abstractions of the entities in a repo such as an interface ICommitTag which models a tag in git (name, SHA,Creator etc). Any part of the code that is dependent on branchs or tags can be mocked and tested however the parts of the code that create branches or tags or do any operation that results in a state change in the repo can't be tested reliably and I am encountering issues on releases where some of these functions are failing for corner cases which means I am relying on functional testing to check that these parts of the app are working.

When I say any part of the code that is dependent on branches or tags I mean that I use an interface

interface ICommitTagSource
{
    IEnumerable<ICommitTag> GetAllTags();
}

When I am testing code that is dependent on tags, the method under test resolves (using prism IoC) an instance of ICommitTagSource and in my unit test I create mock values for ICommitTag and a mock instance of ICommitTagSource that returns the mocked commit tags. Mocking is done using moq. The unit test then registers the mock instances.

Can anyone provide some strategy on how I can reliably test the parts of my app that are responsible for state changes in a repo, is there a general strategy for testing something like this?

I have tried using test repos however my problem there is that I need so many repos to test the various parts that its hard to manage. The tests are cumbersome and not the most reliable because previous executions of tests change the state. Issues I have ran into are tests which should create branches failing due to branches existing already from a previous test where the branch was not deleted after test.

  • 2
    IMHO create a test fixture to destroy and create a fresh blank repository. Then ensure all tests work on unique branches / tags. – Jeremy Lakeman Feb 03 '22 at 07:53
  • I din't think of this! Its simple! Thank you I think this is actually the solution maybe deleting history is what I need to do https://stackoverflow.com/questions/13716658/how-to-delete-all-commit-history-in-github – andrew murphy Feb 03 '22 at 07:56
  • Do not delete history, just create a fresh new local repository, put it on the desire state and test everything with this repo. If you need to have a github repository, you can create one dedicated to your test. – Ôrel Feb 03 '22 at 09:20
  • git != github. I thought you only needed to test locally. But if you start with a blank local repo, you could add remote, and force push a new empty history to a private repo. – Jeremy Lakeman Feb 03 '22 at 10:47

0 Answers0