I'm fairly old fashioned at times ... but should I embrace unit testing?
-
I'm old too. Had a manager who was into TDD. He said things like "write the test before the method" How in the blue heck am I supposed to write a test for something I haven't figured out what it's supposed to do yet? Mercifully he moved to Washington state then Idaho. Don't have to deal with him anymore.
I’ve given up trying to be calm. However, I am open to feeling slightly less agitated.
MarkTJohnson wrote:
How in the blue heck am I supposed to write a test for something I haven't figured out what it's supposed to do yet?
You don't. You must define the contract you're testing in its entirety before you can write a test for it. Otherwise (as you said), how do you know what to test? If the contract evolves, so must the tests. /ravi
My new year resolution: 2048 x 1536 Home | Articles | My .NET bits | Freeware ravib(at)ravib(dot)com
-
At the moment, when I create a public class called Foo, I also create a static test class called FooTester which exercises the public members of the class as best I can. For example, my non-contiguous range class Range has a RangeTest class that looks like this:
public static string Run() { try { testsRun = 0; testsPassed = 0; testsFailed = 0; outText.Clear(); Range ra = new Range(0, 4); // Range rb = new Range(5, 9); // Contiguous with ra Range rc = new Range(10, 14); // Contiguous with rb Range rd = new Range(1, 3); // Intersects ra, not contiguous with rb Range re = new Range(6, 8); // Intersects rb, not contiguous with rc Range rf = new Range(16, 19); // Not contiguous with anything. Range rg = new Range(0, 0); // Single element. Range rh = new Range(1, 1); // Single element. Range ri = new Range(2, 2); // Single element. Range rj = new Range(0, 19); // All elements. Range rk = new Range(0, 4); // Identical to ra CheckInt(ra.Count, 5); CheckInt(ra.Min, 0); CheckInt(ra.Max, 4); CheckString(ra, "(0:4)"); CheckString(ra.UnionWith(re), "(0:4) | (6:8)"); Check(Range.GetEmpty(), new int\[0\]); Check(ra, new int\[\] { 0, 1, 2, 3, 4, }); Check(new Range(new int\[\] { 0, 1, 2, 5, 6, 7 }.AsEnumerable()), new int\[\] { 0, 1, 2, 5, 6, 7 }); Check(ra.UnionWith(ra), new int\[\] { 0, 1, 2, 3, 4 }); Check(ra.UnionWith(rb), new int\[\] { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 }); Check(rb.UnionWith(rc), new int\[\] { 5, 6, 7, 8, 9, 10, 11, 12, 13, 14 }); Check(ra.UnionWith(rc), new int\[\] { 0, 1, 2, 3, 4, 10, 11, 12, 13, 14 }); Check(ra.UnionWith(re), new int\[\] { 0, 1, 2, 3, 4, 6, 7, 8 }); Check(ra.UnionWith(rg), new int\[\] { 0, 1, 2, 3, 4 }); Check(rb.UnionWith(rg), new int\[\] { 0, 5, 6, 7, 8, 9 }); Check(rg.UnionWith(rh).UnionWith(ri), new int\[\] { 0, 1, 2 }); CheckInt(ra.UnionWith(rc).Count, 10); CheckInt(ra.UnionWith(rc).Min, 0); CheckInt(ra.UnionWith
I :laugh: and :laugh: reading the comments here, old farts who are set in their ways - who basically do what the cool aid drinkers want to call by a new name TDD - almost completely done, I once had an agile "evangelist" asses our methods and conclude that we already do close to agile (same methodology I had been using for 30+ years), she left us alone and concentrated on another team, poor bastards. Stick with what you know and do, it works, it is tried and tested and your in depth knowledge of how it works is invaluable.
Never underestimate the power of human stupidity - RAH I'm old. I know stuff - JSOP
-
At the moment, when I create a public class called Foo, I also create a static test class called FooTester which exercises the public members of the class as best I can. For example, my non-contiguous range class Range has a RangeTest class that looks like this:
public static string Run() { try { testsRun = 0; testsPassed = 0; testsFailed = 0; outText.Clear(); Range ra = new Range(0, 4); // Range rb = new Range(5, 9); // Contiguous with ra Range rc = new Range(10, 14); // Contiguous with rb Range rd = new Range(1, 3); // Intersects ra, not contiguous with rb Range re = new Range(6, 8); // Intersects rb, not contiguous with rc Range rf = new Range(16, 19); // Not contiguous with anything. Range rg = new Range(0, 0); // Single element. Range rh = new Range(1, 1); // Single element. Range ri = new Range(2, 2); // Single element. Range rj = new Range(0, 19); // All elements. Range rk = new Range(0, 4); // Identical to ra CheckInt(ra.Count, 5); CheckInt(ra.Min, 0); CheckInt(ra.Max, 4); CheckString(ra, "(0:4)"); CheckString(ra.UnionWith(re), "(0:4) | (6:8)"); Check(Range.GetEmpty(), new int\[0\]); Check(ra, new int\[\] { 0, 1, 2, 3, 4, }); Check(new Range(new int\[\] { 0, 1, 2, 5, 6, 7 }.AsEnumerable()), new int\[\] { 0, 1, 2, 5, 6, 7 }); Check(ra.UnionWith(ra), new int\[\] { 0, 1, 2, 3, 4 }); Check(ra.UnionWith(rb), new int\[\] { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 }); Check(rb.UnionWith(rc), new int\[\] { 5, 6, 7, 8, 9, 10, 11, 12, 13, 14 }); Check(ra.UnionWith(rc), new int\[\] { 0, 1, 2, 3, 4, 10, 11, 12, 13, 14 }); Check(ra.UnionWith(re), new int\[\] { 0, 1, 2, 3, 4, 6, 7, 8 }); Check(ra.UnionWith(rg), new int\[\] { 0, 1, 2, 3, 4 }); Check(rb.UnionWith(rg), new int\[\] { 0, 5, 6, 7, 8, 9 }); Check(rg.UnionWith(rh).UnionWith(ri), new int\[\] { 0, 1, 2 }); CheckInt(ra.UnionWith(rc).Count, 10); CheckInt(ra.UnionWith(rc).Min, 0); CheckInt(ra.UnionWith
OriginalGriff wrote:
Or are you all philistines who don't automate tests at all?
The one time I automated a test, it was to verify I'd addressed all of the memory leaks in my UI application, written in C#. I'd discovered that the mechanism I was using for navigation leaked memory depending upon how the user navigated the application. Fixing the problem was the death of a thousand cuts. Every navigation destination could potentially leak bindings or event handlers, causing memory to not be garbage-collected. This problem showed up only when the application had been running for several days (it's a control app for a machine). My 'automated test' was a little bit of code that woke up every half a second and navigated to a random destination. I ran the test on a couple machines over the course of a week. At the end of the test, the UI was still bopping about a couple times a second. The peak working set was about 150% of the initial working set after the app started up. I viewed it as a successful test.
Software Zen:
delete this;
-
I :laugh: and :laugh: reading the comments here, old farts who are set in their ways - who basically do what the cool aid drinkers want to call by a new name TDD - almost completely done, I once had an agile "evangelist" asses our methods and conclude that we already do close to agile (same methodology I had been using for 30+ years), she left us alone and concentrated on another team, poor bastards. Stick with what you know and do, it works, it is tried and tested and your in depth knowledge of how it works is invaluable.
Never underestimate the power of human stupidity - RAH I'm old. I know stuff - JSOP
That evangelist sounds like one of the better ones. Recognize your existing methodology is OK - and not inventing a stupid recommendation to change something simply because she want to justify her own cost. Unfortunately the SAFe consultant at my previous employer did not have that skill (though from what I hear, they got rid of that crap after I left - as soon as the manager who introduced it moved on).
-
I'm old too. Had a manager who was into TDD. He said things like "write the test before the method" How in the blue heck am I supposed to write a test for something I haven't figured out what it's supposed to do yet? Mercifully he moved to Washington state then Idaho. Don't have to deal with him anymore.
I’ve given up trying to be calm. However, I am open to feeling slightly less agitated.
TDD: 1. Write a test 2. Start writing the code 3. Change the test 4. Write some more code 5. Go back to step 3 as required 6. Finish the code. 7. Fix the bugs in the test. That said, thinking about tests early do help me think "what are the edge cases here" etc. And a few times I do write test first if it is obvious what they should be. As with anything, as soon as you become pedantic you are in for pain.
-
At the moment, when I create a public class called Foo, I also create a static test class called FooTester which exercises the public members of the class as best I can. For example, my non-contiguous range class Range has a RangeTest class that looks like this:
public static string Run() { try { testsRun = 0; testsPassed = 0; testsFailed = 0; outText.Clear(); Range ra = new Range(0, 4); // Range rb = new Range(5, 9); // Contiguous with ra Range rc = new Range(10, 14); // Contiguous with rb Range rd = new Range(1, 3); // Intersects ra, not contiguous with rb Range re = new Range(6, 8); // Intersects rb, not contiguous with rc Range rf = new Range(16, 19); // Not contiguous with anything. Range rg = new Range(0, 0); // Single element. Range rh = new Range(1, 1); // Single element. Range ri = new Range(2, 2); // Single element. Range rj = new Range(0, 19); // All elements. Range rk = new Range(0, 4); // Identical to ra CheckInt(ra.Count, 5); CheckInt(ra.Min, 0); CheckInt(ra.Max, 4); CheckString(ra, "(0:4)"); CheckString(ra.UnionWith(re), "(0:4) | (6:8)"); Check(Range.GetEmpty(), new int\[0\]); Check(ra, new int\[\] { 0, 1, 2, 3, 4, }); Check(new Range(new int\[\] { 0, 1, 2, 5, 6, 7 }.AsEnumerable()), new int\[\] { 0, 1, 2, 5, 6, 7 }); Check(ra.UnionWith(ra), new int\[\] { 0, 1, 2, 3, 4 }); Check(ra.UnionWith(rb), new int\[\] { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 }); Check(rb.UnionWith(rc), new int\[\] { 5, 6, 7, 8, 9, 10, 11, 12, 13, 14 }); Check(ra.UnionWith(rc), new int\[\] { 0, 1, 2, 3, 4, 10, 11, 12, 13, 14 }); Check(ra.UnionWith(re), new int\[\] { 0, 1, 2, 3, 4, 6, 7, 8 }); Check(ra.UnionWith(rg), new int\[\] { 0, 1, 2, 3, 4 }); Check(rb.UnionWith(rg), new int\[\] { 0, 5, 6, 7, 8, 9 }); Check(rg.UnionWith(rh).UnionWith(ri), new int\[\] { 0, 1, 2 }); CheckInt(ra.UnionWith(rc).Count, 10); CheckInt(ra.UnionWith(rc).Min, 0); CheckInt(ra.UnionWith
You are not ignoring unit testing. You are unit testing. While there are framework that I would probably use instead, they are not any more or less "unit test" than your code. The only reason I would use them over something like you do is they are "kind of standardized" these days and hook into toolchains easily. Kind of nice when setting up a build pipeline you can just tell it to "run the test" and then it will take care of showing the result and stop the build if the test fails - or in VS you can just see the highlighted failing test and say "debug this". But of course if you know how to do what you are doing now, and would need to spend half an hour learning "the other way" that benefit is gone. Most "new things" like agile, unit testing, microservices, ... are not new things. They are old things that are assigned a name when they become common enough to warrant a name for easier communication. Once I realized this, I got less annoyed when people "invent" new things. Had a recruiter once saying "oh, you must have seen a lot of changes in your 20+ years". Ehh. No. Not really.
-
At the moment, when I create a public class called Foo, I also create a static test class called FooTester which exercises the public members of the class as best I can. For example, my non-contiguous range class Range has a RangeTest class that looks like this:
public static string Run() { try { testsRun = 0; testsPassed = 0; testsFailed = 0; outText.Clear(); Range ra = new Range(0, 4); // Range rb = new Range(5, 9); // Contiguous with ra Range rc = new Range(10, 14); // Contiguous with rb Range rd = new Range(1, 3); // Intersects ra, not contiguous with rb Range re = new Range(6, 8); // Intersects rb, not contiguous with rc Range rf = new Range(16, 19); // Not contiguous with anything. Range rg = new Range(0, 0); // Single element. Range rh = new Range(1, 1); // Single element. Range ri = new Range(2, 2); // Single element. Range rj = new Range(0, 19); // All elements. Range rk = new Range(0, 4); // Identical to ra CheckInt(ra.Count, 5); CheckInt(ra.Min, 0); CheckInt(ra.Max, 4); CheckString(ra, "(0:4)"); CheckString(ra.UnionWith(re), "(0:4) | (6:8)"); Check(Range.GetEmpty(), new int\[0\]); Check(ra, new int\[\] { 0, 1, 2, 3, 4, }); Check(new Range(new int\[\] { 0, 1, 2, 5, 6, 7 }.AsEnumerable()), new int\[\] { 0, 1, 2, 5, 6, 7 }); Check(ra.UnionWith(ra), new int\[\] { 0, 1, 2, 3, 4 }); Check(ra.UnionWith(rb), new int\[\] { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 }); Check(rb.UnionWith(rc), new int\[\] { 5, 6, 7, 8, 9, 10, 11, 12, 13, 14 }); Check(ra.UnionWith(rc), new int\[\] { 0, 1, 2, 3, 4, 10, 11, 12, 13, 14 }); Check(ra.UnionWith(re), new int\[\] { 0, 1, 2, 3, 4, 6, 7, 8 }); Check(ra.UnionWith(rg), new int\[\] { 0, 1, 2, 3, 4 }); Check(rb.UnionWith(rg), new int\[\] { 0, 5, 6, 7, 8, 9 }); Check(rg.UnionWith(rh).UnionWith(ri), new int\[\] { 0, 1, 2 }); CheckInt(ra.UnionWith(rc).Count, 10); CheckInt(ra.UnionWith(rc).Min, 0); CheckInt(ra.UnionWith
You’re basically doing all the hard work that any self-respecting dev should do with testing so shifting to TDD would be no effort. But I would watch Ian Cooper on YouTube, “where did it all go wrong” and maybe read the best book on it (Kent Becks) as many have mis-represented his words of wisdom. TDD will speed you up if done right.
-
At the moment, when I create a public class called Foo, I also create a static test class called FooTester which exercises the public members of the class as best I can. For example, my non-contiguous range class Range has a RangeTest class that looks like this:
public static string Run() { try { testsRun = 0; testsPassed = 0; testsFailed = 0; outText.Clear(); Range ra = new Range(0, 4); // Range rb = new Range(5, 9); // Contiguous with ra Range rc = new Range(10, 14); // Contiguous with rb Range rd = new Range(1, 3); // Intersects ra, not contiguous with rb Range re = new Range(6, 8); // Intersects rb, not contiguous with rc Range rf = new Range(16, 19); // Not contiguous with anything. Range rg = new Range(0, 0); // Single element. Range rh = new Range(1, 1); // Single element. Range ri = new Range(2, 2); // Single element. Range rj = new Range(0, 19); // All elements. Range rk = new Range(0, 4); // Identical to ra CheckInt(ra.Count, 5); CheckInt(ra.Min, 0); CheckInt(ra.Max, 4); CheckString(ra, "(0:4)"); CheckString(ra.UnionWith(re), "(0:4) | (6:8)"); Check(Range.GetEmpty(), new int\[0\]); Check(ra, new int\[\] { 0, 1, 2, 3, 4, }); Check(new Range(new int\[\] { 0, 1, 2, 5, 6, 7 }.AsEnumerable()), new int\[\] { 0, 1, 2, 5, 6, 7 }); Check(ra.UnionWith(ra), new int\[\] { 0, 1, 2, 3, 4 }); Check(ra.UnionWith(rb), new int\[\] { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 }); Check(rb.UnionWith(rc), new int\[\] { 5, 6, 7, 8, 9, 10, 11, 12, 13, 14 }); Check(ra.UnionWith(rc), new int\[\] { 0, 1, 2, 3, 4, 10, 11, 12, 13, 14 }); Check(ra.UnionWith(re), new int\[\] { 0, 1, 2, 3, 4, 6, 7, 8 }); Check(ra.UnionWith(rg), new int\[\] { 0, 1, 2, 3, 4 }); Check(rb.UnionWith(rg), new int\[\] { 0, 5, 6, 7, 8, 9 }); Check(rg.UnionWith(rh).UnionWith(ri), new int\[\] { 0, 1, 2 }); CheckInt(ra.UnionWith(rc).Count, 10); CheckInt(ra.UnionWith(rc).Min, 0); CheckInt(ra.UnionWith
For me, there are two primary benefits: 1. Communicating intent -- using a well-known testing framework (as opposed to rolling your own) more easily communicates to other people what the testing code is supposed to do, because it's using a standard language. 2. Integration -- such as with an automated build pipeline, or Visual Studio's Test Explorer.
-
We did some unit testing with Nunit in the past, but it proved too time-consuming to keep up with the rapid pace of changes of our software. So I think the idea is good, but not for our situation (small team, rapid changes) I also shiver when I read articles about "Test Driven Development" :-\ Oh, and of course the obligatory: Slant: best-unit-testing-frameworks-for-net[^]
I've heard this cry before: "the tests are brittle! every time we update prod code, we have to fix heaps of tests!" and it usually leads to people feeling that unit testing "doesn't work for them". The situation you describe is usually indicative of just not having had someone with extensive unit-testing experience to help write the tests in a sustainable manner. It's not a swipe at the people writing the code - it's really easy to get to the state where an update to code breaks a hundred tests without the experience on how to mitigate that. It's also easier (imo) to write sustainable tests if you're writing them _first_, because this drives your software design to be more testable - and often, produce more resilient tests. Following SOLID principles helps a lot because it means you can mock out layers underneath the code being tested instead of relying on actual behaviors all the time. It also means you can focus testing on smaller units up-front. If you decide to give it another go, try leading with this mindset: if these tests are brittle, how do we make it so that they aren't? What architectural/design changes should we do to facilitate resilient, informative tests?
------------------------------------------------ If you say that getting the money is the most important thing You will spend your life completely wasting your time You will be doing things you don't like doing In order to go on living That is, to go on doing things you don't like doing Which is stupid. - Alan Watts https://www.youtube.com/watch?v=-gXTZM\_uPMY
-
At the moment, when I create a public class called Foo, I also create a static test class called FooTester which exercises the public members of the class as best I can. For example, my non-contiguous range class Range has a RangeTest class that looks like this:
public static string Run() { try { testsRun = 0; testsPassed = 0; testsFailed = 0; outText.Clear(); Range ra = new Range(0, 4); // Range rb = new Range(5, 9); // Contiguous with ra Range rc = new Range(10, 14); // Contiguous with rb Range rd = new Range(1, 3); // Intersects ra, not contiguous with rb Range re = new Range(6, 8); // Intersects rb, not contiguous with rc Range rf = new Range(16, 19); // Not contiguous with anything. Range rg = new Range(0, 0); // Single element. Range rh = new Range(1, 1); // Single element. Range ri = new Range(2, 2); // Single element. Range rj = new Range(0, 19); // All elements. Range rk = new Range(0, 4); // Identical to ra CheckInt(ra.Count, 5); CheckInt(ra.Min, 0); CheckInt(ra.Max, 4); CheckString(ra, "(0:4)"); CheckString(ra.UnionWith(re), "(0:4) | (6:8)"); Check(Range.GetEmpty(), new int\[0\]); Check(ra, new int\[\] { 0, 1, 2, 3, 4, }); Check(new Range(new int\[\] { 0, 1, 2, 5, 6, 7 }.AsEnumerable()), new int\[\] { 0, 1, 2, 5, 6, 7 }); Check(ra.UnionWith(ra), new int\[\] { 0, 1, 2, 3, 4 }); Check(ra.UnionWith(rb), new int\[\] { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 }); Check(rb.UnionWith(rc), new int\[\] { 5, 6, 7, 8, 9, 10, 11, 12, 13, 14 }); Check(ra.UnionWith(rc), new int\[\] { 0, 1, 2, 3, 4, 10, 11, 12, 13, 14 }); Check(ra.UnionWith(re), new int\[\] { 0, 1, 2, 3, 4, 6, 7, 8 }); Check(ra.UnionWith(rg), new int\[\] { 0, 1, 2, 3, 4 }); Check(rb.UnionWith(rg), new int\[\] { 0, 5, 6, 7, 8, 9 }); Check(rg.UnionWith(rh).UnionWith(ri), new int\[\] { 0, 1, 2 }); CheckInt(ra.UnionWith(rc).Count, 10); CheckInt(ra.UnionWith(rc).Min, 0); CheckInt(ra.UnionWith
Any testing is far better than no testing. You could put this test into an automated runner and have at it - you have "unit tests" where the definition of "unit" is stretched out a little :D and you already gain something out of this - if it's run in a CI environment, you get to catch bugs before they go out. Even if you just run them yourself, you get that benefit, though you could forget. Now, if you decide that you have the time and energy to convert to more focused tests, or decide that new tests could be written in a more focused manner, there are advantages: - more focused test failures - failures now tell you exactly _what_ has failed, instead of just "there's been a regression" - reporting output showing [Test Name] [passed/failed] for posterity - easier to fix the issue - find the single test, look at what it does, what environment it had to set up, and run through just that code path in the debugger to find the issue. I'll vote up unit tests, especially written _before_ the prod code (TDD!) any day of the week - and the weekend! :D
------------------------------------------------ If you say that getting the money is the most important thing You will spend your life completely wasting your time You will be doing things you don't like doing In order to go on living That is, to go on doing things you don't like doing Which is stupid. - Alan Watts https://www.youtube.com/watch?v=-gXTZM\_uPMY
-
I've heard this cry before: "the tests are brittle! every time we update prod code, we have to fix heaps of tests!" and it usually leads to people feeling that unit testing "doesn't work for them". The situation you describe is usually indicative of just not having had someone with extensive unit-testing experience to help write the tests in a sustainable manner. It's not a swipe at the people writing the code - it's really easy to get to the state where an update to code breaks a hundred tests without the experience on how to mitigate that. It's also easier (imo) to write sustainable tests if you're writing them _first_, because this drives your software design to be more testable - and often, produce more resilient tests. Following SOLID principles helps a lot because it means you can mock out layers underneath the code being tested instead of relying on actual behaviors all the time. It also means you can focus testing on smaller units up-front. If you decide to give it another go, try leading with this mindset: if these tests are brittle, how do we make it so that they aren't? What architectural/design changes should we do to facilitate resilient, informative tests?
------------------------------------------------ If you say that getting the money is the most important thing You will spend your life completely wasting your time You will be doing things you don't like doing In order to go on living That is, to go on doing things you don't like doing Which is stupid. - Alan Watts https://www.youtube.com/watch?v=-gXTZM\_uPMY
Guess it depends on how disciplined the co-workers are, in my team they are not, they're a real wild bunch that break the API almost every day :-\
-
Guess it depends on how disciplined the co-workers are, in my team they are not, they're a real wild bunch that break the API almost every day :-\
If you have good refactoring available, that can help (Rider/ReSharper) because at least it will try to update all usages - often with little or no manual work involved. If you find that you're often breaking the shape of your API, then create a class in your tests - an adapter - that keeps the api exposed to the tests the same, providing a central place to respond to breaking changes. However, if your API is constantly changing (mutating, not just being expanded upon), I really hope there's only one consumer - I'd hate to be the one having to chase that down the line! This could suggest altering the dev behavior to not be so "wild", or just making people responsible for completing the refactor themselves - if there's a designated "unit test person" in the group and no-one else bothers to write tests, that's never going to end well.
------------------------------------------------ If you say that getting the money is the most important thing You will spend your life completely wasting your time You will be doing things you don't like doing In order to go on living That is, to go on doing things you don't like doing Which is stupid. - Alan Watts https://www.youtube.com/watch?v=-gXTZM\_uPMY
-
If you have good refactoring available, that can help (Rider/ReSharper) because at least it will try to update all usages - often with little or no manual work involved. If you find that you're often breaking the shape of your API, then create a class in your tests - an adapter - that keeps the api exposed to the tests the same, providing a central place to respond to breaking changes. However, if your API is constantly changing (mutating, not just being expanded upon), I really hope there's only one consumer - I'd hate to be the one having to chase that down the line! This could suggest altering the dev behavior to not be so "wild", or just making people responsible for completing the refactor themselves - if there's a designated "unit test person" in the group and no-one else bothers to write tests, that's never going to end well.
------------------------------------------------ If you say that getting the money is the most important thing You will spend your life completely wasting your time You will be doing things you don't like doing In order to go on living That is, to go on doing things you don't like doing Which is stupid. - Alan Watts https://www.youtube.com/watch?v=-gXTZM\_uPMY
I installed this utility (which works really well) on our TeamCity builder to check for API changes: GitHub - arlm/apichange: Fork of the codeplex API Change repository[^] But they just keep breaking away despite the warnings :sigh:
-
I installed this utility (which works really well) on our TeamCity builder to check for API changes: GitHub - arlm/apichange: Fork of the codeplex API Change repository[^] But they just keep breaking away despite the warnings :sigh:
That's a team problem then. Just like how git can't police people into making concise, responsible commits in the right places, and wasn't designed to, that tool is to warn people _who actually care when stuff breaks_. If your cowboys don't care, that's a whole other issue that needs to be figured out, because they're creating work for other people. That doesn't mean that an api _cannot_ change - it means that the people involved have to do so responsibly - eg by providing overloads, or at least trying to keep existing signatures as intact as possible. I'm not a fan of it, but perhaps you need something like gated checkins. I'd much rather have the team chat where we all come to an agreement on how we're going to work together though. You need to sell this idea of improving team cohesion up the chain - because right now, the cowboys are costing the company money when other people have to deal with their fallout.
------------------------------------------------ If you say that getting the money is the most important thing You will spend your life completely wasting your time You will be doing things you don't like doing In order to go on living That is, to go on doing things you don't like doing Which is stupid. - Alan Watts https://www.youtube.com/watch?v=-gXTZM\_uPMY
-
At the moment, when I create a public class called Foo, I also create a static test class called FooTester which exercises the public members of the class as best I can. For example, my non-contiguous range class Range has a RangeTest class that looks like this:
public static string Run() { try { testsRun = 0; testsPassed = 0; testsFailed = 0; outText.Clear(); Range ra = new Range(0, 4); // Range rb = new Range(5, 9); // Contiguous with ra Range rc = new Range(10, 14); // Contiguous with rb Range rd = new Range(1, 3); // Intersects ra, not contiguous with rb Range re = new Range(6, 8); // Intersects rb, not contiguous with rc Range rf = new Range(16, 19); // Not contiguous with anything. Range rg = new Range(0, 0); // Single element. Range rh = new Range(1, 1); // Single element. Range ri = new Range(2, 2); // Single element. Range rj = new Range(0, 19); // All elements. Range rk = new Range(0, 4); // Identical to ra CheckInt(ra.Count, 5); CheckInt(ra.Min, 0); CheckInt(ra.Max, 4); CheckString(ra, "(0:4)"); CheckString(ra.UnionWith(re), "(0:4) | (6:8)"); Check(Range.GetEmpty(), new int\[0\]); Check(ra, new int\[\] { 0, 1, 2, 3, 4, }); Check(new Range(new int\[\] { 0, 1, 2, 5, 6, 7 }.AsEnumerable()), new int\[\] { 0, 1, 2, 5, 6, 7 }); Check(ra.UnionWith(ra), new int\[\] { 0, 1, 2, 3, 4 }); Check(ra.UnionWith(rb), new int\[\] { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 }); Check(rb.UnionWith(rc), new int\[\] { 5, 6, 7, 8, 9, 10, 11, 12, 13, 14 }); Check(ra.UnionWith(rc), new int\[\] { 0, 1, 2, 3, 4, 10, 11, 12, 13, 14 }); Check(ra.UnionWith(re), new int\[\] { 0, 1, 2, 3, 4, 6, 7, 8 }); Check(ra.UnionWith(rg), new int\[\] { 0, 1, 2, 3, 4 }); Check(rb.UnionWith(rg), new int\[\] { 0, 5, 6, 7, 8, 9 }); Check(rg.UnionWith(rh).UnionWith(ri), new int\[\] { 0, 1, 2 }); CheckInt(ra.UnionWith(rc).Count, 10); CheckInt(ra.UnionWith(rc).Min, 0); CheckInt(ra.UnionWith
Agile programming doesn't lend itself to unit testing. Since the "customer" is involved, they are only concerned about the speed of development, and whether or not a task can be completed within a sprint. For us, a sprint also includes the time testers and customers need to test a given task. We don't have any time to do unit test development because we're just trying to get the code written. Another aspect is that most of our business rules are implemented in the database. Even if they weren't, they change (at the customer's request) so often that writing a unit test for a given business rule is pointless. We would have to write an app that did nothing but spot-check data (we have 54 million records, and it would take HOURS to check them all). Our apps are all web apps, and we have way over the top security restrictions. - We can't use the browser dev console on test, QA, or production environments - We don't have any access to the databases on those environments - All four environments (the ones already cited, and dev) are configured differently in terms of memory, cpu's, hand hard drive space and number of servers. If something happens on test/qa/prod, but not on dev, it's a freakin nightmare because we can't use the dev console on to see what's happening in the javascript to narrow it down. Our infrastructure is the cause of many of our problems, and we can't leverage any tools to find out what's wrong, and unit testing won't help in that regard.
".45 ACP - because shooting twice is just silly" - JSOP, 2010
-----
You can never have too much ammo - unless you're swimming, or on fire. - JSOP, 2010
-----
When you pry the gun from my cold dead hands, be careful - the barrel will be very hot. - JSOP, 2013 -
At the moment, when I create a public class called Foo, I also create a static test class called FooTester which exercises the public members of the class as best I can. For example, my non-contiguous range class Range has a RangeTest class that looks like this:
public static string Run() { try { testsRun = 0; testsPassed = 0; testsFailed = 0; outText.Clear(); Range ra = new Range(0, 4); // Range rb = new Range(5, 9); // Contiguous with ra Range rc = new Range(10, 14); // Contiguous with rb Range rd = new Range(1, 3); // Intersects ra, not contiguous with rb Range re = new Range(6, 8); // Intersects rb, not contiguous with rc Range rf = new Range(16, 19); // Not contiguous with anything. Range rg = new Range(0, 0); // Single element. Range rh = new Range(1, 1); // Single element. Range ri = new Range(2, 2); // Single element. Range rj = new Range(0, 19); // All elements. Range rk = new Range(0, 4); // Identical to ra CheckInt(ra.Count, 5); CheckInt(ra.Min, 0); CheckInt(ra.Max, 4); CheckString(ra, "(0:4)"); CheckString(ra.UnionWith(re), "(0:4) | (6:8)"); Check(Range.GetEmpty(), new int\[0\]); Check(ra, new int\[\] { 0, 1, 2, 3, 4, }); Check(new Range(new int\[\] { 0, 1, 2, 5, 6, 7 }.AsEnumerable()), new int\[\] { 0, 1, 2, 5, 6, 7 }); Check(ra.UnionWith(ra), new int\[\] { 0, 1, 2, 3, 4 }); Check(ra.UnionWith(rb), new int\[\] { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 }); Check(rb.UnionWith(rc), new int\[\] { 5, 6, 7, 8, 9, 10, 11, 12, 13, 14 }); Check(ra.UnionWith(rc), new int\[\] { 0, 1, 2, 3, 4, 10, 11, 12, 13, 14 }); Check(ra.UnionWith(re), new int\[\] { 0, 1, 2, 3, 4, 6, 7, 8 }); Check(ra.UnionWith(rg), new int\[\] { 0, 1, 2, 3, 4 }); Check(rb.UnionWith(rg), new int\[\] { 0, 5, 6, 7, 8, 9 }); Check(rg.UnionWith(rh).UnionWith(ri), new int\[\] { 0, 1, 2 }); CheckInt(ra.UnionWith(rc).Count, 10); CheckInt(ra.UnionWith(rc).Min, 0); CheckInt(ra.UnionWith
Read the stuff at the top of the page: the Lounge is not for coding questions. Post it here instead: Ask a Question[^] Ignoring the rules and annoying people you want free help from is not a good idea ... In addition, when you post your question give us just the relevant code fragments, and paste them directly into the question. Without it, we have no idea what you have tried, and it saves us teh effort of trying to work out which bits of your whole code are important. The more you help us to help you, the better the answer you can get. Well, well, well, how the turntables!* :D * I know it's not completely relevant, but I probably won't get a better chance than this.
Best, Sander Azure DevOps Succinctly (free eBook) Azure Serverless Succinctly (free eBook) Migrating Apps to the Cloud with Azure arrgh.js - Bringing LINQ to JavaScript
-
Read the stuff at the top of the page: the Lounge is not for coding questions. Post it here instead: Ask a Question[^] Ignoring the rules and annoying people you want free help from is not a good idea ... In addition, when you post your question give us just the relevant code fragments, and paste them directly into the question. Without it, we have no idea what you have tried, and it saves us teh effort of trying to work out which bits of your whole code are important. The more you help us to help you, the better the answer you can get. Well, well, well, how the turntables!* :D * I know it's not completely relevant, but I probably won't get a better chance than this.
Best, Sander Azure DevOps Succinctly (free eBook) Azure Serverless Succinctly (free eBook) Migrating Apps to the Cloud with Azure arrgh.js - Bringing LINQ to JavaScript
:laugh:
"I have no idea what I did, but I'm taking full credit for it." - ThisOldTony "Common sense is so rare these days, it should be classified as a super power" - Random T-shirt AntiTwitter: @DalekDave is now a follower!
-
At the moment, when I create a public class called Foo, I also create a static test class called FooTester which exercises the public members of the class as best I can. For example, my non-contiguous range class Range has a RangeTest class that looks like this:
public static string Run() { try { testsRun = 0; testsPassed = 0; testsFailed = 0; outText.Clear(); Range ra = new Range(0, 4); // Range rb = new Range(5, 9); // Contiguous with ra Range rc = new Range(10, 14); // Contiguous with rb Range rd = new Range(1, 3); // Intersects ra, not contiguous with rb Range re = new Range(6, 8); // Intersects rb, not contiguous with rc Range rf = new Range(16, 19); // Not contiguous with anything. Range rg = new Range(0, 0); // Single element. Range rh = new Range(1, 1); // Single element. Range ri = new Range(2, 2); // Single element. Range rj = new Range(0, 19); // All elements. Range rk = new Range(0, 4); // Identical to ra CheckInt(ra.Count, 5); CheckInt(ra.Min, 0); CheckInt(ra.Max, 4); CheckString(ra, "(0:4)"); CheckString(ra.UnionWith(re), "(0:4) | (6:8)"); Check(Range.GetEmpty(), new int\[0\]); Check(ra, new int\[\] { 0, 1, 2, 3, 4, }); Check(new Range(new int\[\] { 0, 1, 2, 5, 6, 7 }.AsEnumerable()), new int\[\] { 0, 1, 2, 5, 6, 7 }); Check(ra.UnionWith(ra), new int\[\] { 0, 1, 2, 3, 4 }); Check(ra.UnionWith(rb), new int\[\] { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 }); Check(rb.UnionWith(rc), new int\[\] { 5, 6, 7, 8, 9, 10, 11, 12, 13, 14 }); Check(ra.UnionWith(rc), new int\[\] { 0, 1, 2, 3, 4, 10, 11, 12, 13, 14 }); Check(ra.UnionWith(re), new int\[\] { 0, 1, 2, 3, 4, 6, 7, 8 }); Check(ra.UnionWith(rg), new int\[\] { 0, 1, 2, 3, 4 }); Check(rb.UnionWith(rg), new int\[\] { 0, 5, 6, 7, 8, 9 }); Check(rg.UnionWith(rh).UnionWith(ri), new int\[\] { 0, 1, 2 }); CheckInt(ra.UnionWith(rc).Count, 10); CheckInt(ra.UnionWith(rc).Min, 0); CheckInt(ra.UnionWith
I'm so old-fashioned that I only recently learned about unit tests and only now learned about automatic testing outside of that. I was out of the mainstream coding world for a quarter of a century while I raised my 6, which is one reason that I'm here - to learn. I think that you should do what works for you unless you are required to do it otherwise. For me and the coding environment I work in, that means lots of echos and prints - var dumping, but that's legacy code for you - don't stir the pot too much xD :laugh:
-
At the moment, when I create a public class called Foo, I also create a static test class called FooTester which exercises the public members of the class as best I can. For example, my non-contiguous range class Range has a RangeTest class that looks like this:
public static string Run() { try { testsRun = 0; testsPassed = 0; testsFailed = 0; outText.Clear(); Range ra = new Range(0, 4); // Range rb = new Range(5, 9); // Contiguous with ra Range rc = new Range(10, 14); // Contiguous with rb Range rd = new Range(1, 3); // Intersects ra, not contiguous with rb Range re = new Range(6, 8); // Intersects rb, not contiguous with rc Range rf = new Range(16, 19); // Not contiguous with anything. Range rg = new Range(0, 0); // Single element. Range rh = new Range(1, 1); // Single element. Range ri = new Range(2, 2); // Single element. Range rj = new Range(0, 19); // All elements. Range rk = new Range(0, 4); // Identical to ra CheckInt(ra.Count, 5); CheckInt(ra.Min, 0); CheckInt(ra.Max, 4); CheckString(ra, "(0:4)"); CheckString(ra.UnionWith(re), "(0:4) | (6:8)"); Check(Range.GetEmpty(), new int\[0\]); Check(ra, new int\[\] { 0, 1, 2, 3, 4, }); Check(new Range(new int\[\] { 0, 1, 2, 5, 6, 7 }.AsEnumerable()), new int\[\] { 0, 1, 2, 5, 6, 7 }); Check(ra.UnionWith(ra), new int\[\] { 0, 1, 2, 3, 4 }); Check(ra.UnionWith(rb), new int\[\] { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 }); Check(rb.UnionWith(rc), new int\[\] { 5, 6, 7, 8, 9, 10, 11, 12, 13, 14 }); Check(ra.UnionWith(rc), new int\[\] { 0, 1, 2, 3, 4, 10, 11, 12, 13, 14 }); Check(ra.UnionWith(re), new int\[\] { 0, 1, 2, 3, 4, 6, 7, 8 }); Check(ra.UnionWith(rg), new int\[\] { 0, 1, 2, 3, 4 }); Check(rb.UnionWith(rg), new int\[\] { 0, 5, 6, 7, 8, 9 }); Check(rg.UnionWith(rh).UnionWith(ri), new int\[\] { 0, 1, 2 }); CheckInt(ra.UnionWith(rc).Count, 10); CheckInt(ra.UnionWith(rc).Min, 0); CheckInt(ra.UnionWith
Unit testing tests for code that is primal and isn't the cause of problems. Test that the value I passed you is a bool. What does cause problems are things like Excel cells that are missing or contains the wrong data. Data configurations that you did not plan/account for. Users that do things you did not think they would ever do. Exceptions you missed that blew up the app. And lets not forget that you are writing test code to test your code. :wtf:
-
At the moment, when I create a public class called Foo, I also create a static test class called FooTester which exercises the public members of the class as best I can. For example, my non-contiguous range class Range has a RangeTest class that looks like this:
public static string Run() { try { testsRun = 0; testsPassed = 0; testsFailed = 0; outText.Clear(); Range ra = new Range(0, 4); // Range rb = new Range(5, 9); // Contiguous with ra Range rc = new Range(10, 14); // Contiguous with rb Range rd = new Range(1, 3); // Intersects ra, not contiguous with rb Range re = new Range(6, 8); // Intersects rb, not contiguous with rc Range rf = new Range(16, 19); // Not contiguous with anything. Range rg = new Range(0, 0); // Single element. Range rh = new Range(1, 1); // Single element. Range ri = new Range(2, 2); // Single element. Range rj = new Range(0, 19); // All elements. Range rk = new Range(0, 4); // Identical to ra CheckInt(ra.Count, 5); CheckInt(ra.Min, 0); CheckInt(ra.Max, 4); CheckString(ra, "(0:4)"); CheckString(ra.UnionWith(re), "(0:4) | (6:8)"); Check(Range.GetEmpty(), new int\[0\]); Check(ra, new int\[\] { 0, 1, 2, 3, 4, }); Check(new Range(new int\[\] { 0, 1, 2, 5, 6, 7 }.AsEnumerable()), new int\[\] { 0, 1, 2, 5, 6, 7 }); Check(ra.UnionWith(ra), new int\[\] { 0, 1, 2, 3, 4 }); Check(ra.UnionWith(rb), new int\[\] { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 }); Check(rb.UnionWith(rc), new int\[\] { 5, 6, 7, 8, 9, 10, 11, 12, 13, 14 }); Check(ra.UnionWith(rc), new int\[\] { 0, 1, 2, 3, 4, 10, 11, 12, 13, 14 }); Check(ra.UnionWith(re), new int\[\] { 0, 1, 2, 3, 4, 6, 7, 8 }); Check(ra.UnionWith(rg), new int\[\] { 0, 1, 2, 3, 4 }); Check(rb.UnionWith(rg), new int\[\] { 0, 5, 6, 7, 8, 9 }); Check(rg.UnionWith(rh).UnionWith(ri), new int\[\] { 0, 1, 2 }); CheckInt(ra.UnionWith(rc).Count, 10); CheckInt(ra.UnionWith(rc).Min, 0); CheckInt(ra.UnionWith
It sounds like what you do is exactly what unit testing is. Perhaps some of the other parts of the Capitalized-Letter "Unit Testing" practices that might come to mind are > keeping selected relevent unit test cases for reuse in either/both future development or qa builds. > running the tests *automatically* against a shared build, especially during heavier development times, shared or otherwise. I don't think these are truly new, but have become more widely recognized and adapted for practically any language. We used to do this stuff in COBOL. Beware of when any programmer makes automating a test ritually - if it's automatic, there should be a reason for the test. Some people mistake statistics for quality. If a case doesn't make sense anymore get rid of the test(s). What's great is there are so much shared knowledge and experience. Frameworks and suggested practices abound. And if you don't happen to use a framework for it, there's really no issue, and it has just as much relevence. Automating tests is essential to expediting refactoring code. It gives me some assurance that unexpected behaviors haven't popped up. Some tests behave like functioning documentation to remind me in the future just how this thing works.