0

I discovered a bug and I want to figure out where it got introduced. The next thing I did was create a unit test that currently fails but should pass when the bug is fixed. I've created a unit test in HEAD and can run it from the command line. But the problem is, if I checkout anything but HEAD, that unit test won't be there. How can I get bisect to run this unit test on every checkout it does even though it only exists in HEAD?

Here are some ideas I have:

  1. I could make the bisect script cherry pick (without committing) the unit test.
  2. If I avoid committing the test, then the test will be brought over to every checkout (I think).

Is there a better way to do this?

EDIT: I'm using Java.

Daniel Kaplan
  • 62,768
  • 50
  • 234
  • 356

1 Answers1

0

Here's a suggestion: write your test so that it doesn't depend on file-paths in your project. Go ahead and version it so that you have a record in history. Then copy the test outside of your project folder, and pass it to bisect run as

git bisect run ../my-test-script
  • That's hard to do. My test is compiled against my project. I think I'd have to make a separate bisect project that depends on my project in order to do that. Maybe I'm wrong, but it doesn't seem worth the effort. – Daniel Kaplan Apr 17 '14 at 21:36
  • 1
    @tieTYT you should mention in your question what technology stack you're using (C#, Java, etc.). This would be an easy thing to do with a dynamic language such as Ruby or Python, since there's no compilation involved. –  Apr 17 '14 at 21:38
  • @tieTYT see my answer to [Automate git bisect for MSBuild/NUnit/.NET/Windows batch commands in msysgit?](http://stackoverflow.com/a/17904200/456814). I wrote a Bash script that automated building and running unit tests for a **C#** project. I'm just passing project and test file paths to `MSBuild` and the NUnit console runner. Can you not do something similar with Java? Like, write a Bash/Ruby/Scala/Whatever script that passes your project files to `javac` to compile, then invoke a unit-test runner? –  Apr 18 '14 at 02:26
  • @tieTYT according to the JUnit team, you can [run JUnit tests from the command-line](https://github.com/junit-team/junit/wiki/Test-runners#console-based-test-runner), for example, like `java org.junit.runner.JUnitCore TestClass1 [...other test classes...]`. –  Apr 18 '14 at 02:30