The site is Java 6.
I've been doing manual tests all the time, but there are limits, right? I ended up writing test code and helped with that estimate.
I started by collecting JUnit and Mockito, but I don't know. I had a hard time because it was too old and I couldn't hit the information easily.
You die if you have too much technical debt? A memorandum as a case.
JUnit 4.11 Speaking of writing test code in Java, JUnit. The latest is JUnit 5, but it can only be used with Java 8 or later, so choose from 4 series. It must be 4.8 or later to use the @Rule annotation described later.
assertJ 1.7.1 Assertion library.
Because it is a style of writing by connecting with a method chain It's hard to become ((((parentheses hell)))) You can write a pompon assert statement according to the Eclipse suggestion.
Mockito 1.9.5 A library that makes it fairly easy to implement test mockups. It seems to read as Mojito. For JUit5 series, there is Mockito 2.x.x, but for JUnit4 series, the stability seems to be 1.9.5.
Suppose you want to test the hogehoge () method of the Hoge class. If the hogehoge () method depends on another Fuga class You can't test without preparing the Fuga class.
When that is the case with a mock "When you see Fuga # fugafuga () from the Hoge class, just return 3." Can be set. It is essential to say test in Java.
PowerMock 1.5.6 Mockito is really useful, but you can't mock static methods. PowerMock hacks it nicely You can mock static methods in a similar way to Mockito. Also private methods.
In the field where Java has been used for a long time, static methods are also available This is also essential because it is terrifying (prejudice).
This Power Mock and Eclemma, which will be described later, were incompatible and I had a hard time. (Solved in the latest version)
I chose 1.5.6 because Mockito 1.9.x and PowerMock 1.5.x are compatible.
Javassist3.18.2 Javassist is a library used when playing with Java bytecode. Java bytecode is the Java source we wrote The one that can be compiled. The one that runs on the JVM.
PowerMock uses this. Java bytecode rather than source It seems that the mock is realized by rewriting it well. (I don't know the details, and this explanation may be incorrect)
Javassist 3.4 is included in the existing project, That was the highest priority, so when I got angry, I was addicted to "What? You're in?"
QuickJUnit Eclipse plugin for writing JUnit. There are various shortcuts and templates.
Eclemma 3.0.1 ** Ecl ** ipse + ** EMMA ** library. A plugin for running EMMA on Eclipse to measure test coverage. Eclemma stopped updating a long time ago and I really wanted to use JaCoCo.
Eclemma and PowerMock 1.5.6 are very incompatible, When I run a test using PowerMock, it shows 0% coverage.
Eclemma looks at the Java bytecode I just described and sees where it was executed. I'm watching PowerMock (to mock static methods) Because (a copy of) that bytecode is edited with Javassist and that is executed.
This problem has been solved for Java8, JUnit5 and later.
By using it instead of RunWith The above "0% coverage problem" can be avoided.
Reference: https://code.i-harness.com/ja/q/1647e8c
This is all (I think) I was able to write test code for several methods, execute it, and measure coverage.
It's still good because it's Java, because it's just hard to find, and if you look for it, it will come out.
Javassist version conflict and PowerMock and Eclemma "0% coverage issue"
Indirectly, because the development environment is that the version of Eclipse is too old & there is no Maven Installing plugins and libraries was very troublesome, and there were problems.
Even if it's a trivial problem one by one If multiple occurrences occur, the time required for resolution will increase immediately.
For JUnit 5 and later, the "0% coverage" problem of PowerMock and Eclemma has been solved.
In other words, it was resolved two years ago in the world, so if you go around with those two keywords now, The way to write RunWith that does not use Rule annotation is more hit. (It seems to be annoying to write in Rule)
I had a hard time making it a procedure, but this testing framework group I don't know if it will be adopted as I suggested.
Above all, it is said that "100% coverage is essential", so I have a bad feeling.
After all, "Writing a test takes time, so let's do a manual test." I came to the conclusion.
What kind of judgment! I mean, I'm making a manual test case! I hate it! !!
Recommended Posts