Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
We don’t allow questions seeking recommendations for books, tools, software libraries, and more. You can edit the question so it can be answered with facts and citations.
Closed 5 years ago.
Improve this question
Is there a good tool to generate unit test cases given say a .NET or Java project, it generates unit test cases that would cover an almost 100% code coverage. The number of test cases could be directly proportional to the cyclomatic complexity of the code (the higher the nesting of loops and conditions the higher the cyclomatic complexity) where the higher the cyclomatic complexity, the greater the set of test cases are generated. I'm not expecting it to be fully functional (say I'm going to build the unit tests and run it after its been generated), but I would say that it can have a template style in the test case where you are to modify the case that suits your intended needs. But it should also have a proper setup and teardown method and is good enough to detect if mock objects for unit testing should be used should there be any dependencies. So, is there such a tool that exists?
For .NET, Microsoft has Pex which will hopefully go mainstream for .NET 4.0, along with Code Contracts. I highly recommend watching the Channel 9 video.
It strikes me that this sort of thing is very good for very data-driven classes - parsers etc. I can't see that I'd very often start off with it, but a useful tool to have in your armoury nonetheless.
For C# (or .NET in general), PEX might be that tool. It works at the IL level, and attempts to force its way into every branch. It has successfully uncovered a wide range of bugs (in the BCL etc).
Although it seems counter-intuituve, you may also be interested in random test generation frameworks. Research has proven that it can be just as effective in finding bugs than systematic approaches based on coverage, as you suggest.
Check out Randoop both for .NET and Java. It works by generating a more or less random sequence of method calls, and checks contracts, crashes etc. It is fully automatic.
Also you may want to check out some other random testing tools based on QuickCheck, e.g. for Java, Scala, F#. that are more similar to Pex, i.e. you give a specification, or parametrized unit test, and the tool checks it for a number of generated input arguments.
I've found that this "parametrized" way of writing unit tests is actually a lot more natural in at least 60% of the cases, and finds lots more bugs.
For Java, you can check EvoSuite, which is open source and currently active (disclaimer, I am one of its contributors). Also see related question for a list of more tools.
For Java, try JUnit-Tools. It has own eclipse plugin along with good documentation.
Related
Closed. This question is off-topic. It is not currently accepting answers.
Want to improve this question? Update the question so it's on-topic for Stack Overflow.
Closed 9 years ago.
Improve this question
I am going to admit that I am battling with changing face of C# and unlearning what I learnt since starting out with C#1.
I started years ago writing greenfield C# 1.1 code and also currently work a lot with maintenance work on code that is written with previous versions of C#.
Being exposed to the old ways of doing things is hard as I am battling to unlearn from code what I have written in the past and that I have to look at daily that was written in previous versions of C#. Having to maintain Java projects also doesn't help as it is similar to C#1. With time I could probably unlearn my bad practices but with project deadlines it is hard to do.
My lazy mind also is against me as its logic says if I use OO and DRY principles and the code compiles my boss is happy and thinks all is good when I am just not simplifying my code with new ways of doing things.
I have started reading Jon Skeet's C# in depth 2ed as what it does it gives the code solutions to do a specific tasks for each of C#1,C#2,C#3,C#4 each time showing the code examples how it simplifies code but I am finding it hard to remember and put into practice these new methods due to having to still deal with all this legacy code daily and still having to balance my jack of all trades dev jobs.
Is there an easy way to refactor between coding practices from C#1,C#2,C#3 to C#4 either on the fly or at compile time and give suggests either in English language or refactor the code for me.
Is there anywhere like a tool or a site I can see the changes for the same code between the C# versions excluding Jon Skeet's C# in depth book?
The latest version of ReSharper would be a helpful tool to move your C# forward in many respects quickly. It will point you to newer practices and make it quicker & less painful to employ them across existing code.
A couple forward-looking ReSharper refactorings that come to mind are:
Static to Extension Method...
Property to Auto Property...
Also, ReSharper will, for example, encourage you to use var for implicit declarations where possible.
CodeRush can do much the same, but I have not used it as recently.
To see the difference between where such tools' refactorings put you and where you started, diffing against prior revisions of your files in source control comes to mind.
For changes to the .NET BCL alongside C# as #stakx points out, consider digging into build warnings regarding deprecated code built against newer versions of .NET. Once you learn (as just one example) to replace uses of System.Xml.XmlValidatingReader with System.Xml.XmlReader, making the change in other places flagged for the former deprecated type will become quick.
What's Obsolete in the .NET Framework on MSDN characterizes the most recent BCL deprecations since .NET 1.1 and how to update affected code.
Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
We don’t allow questions seeking recommendations for books, tools, software libraries, and more. You can edit the question so it can be answered with facts and citations.
Closed 7 years ago.
Improve this question
I'm not sure if this kind of question is appropriate, but its been suggested I ask here, so here goes.
For a subject at university this semester our assignment is to take some existing code and parallelize it. We've got a bit of an open end on it, but open source is really the only way we are going to get existing code. I could write some code and then parallelize it, but existing code (and perhaps one where I could make a genuine contribution) would be best, to avoid doubling my workload for little benefit.
I was hoping to use C# and make use of the new Task parallel library, but I'm struggling to find some C# open source projects that are computationally expensive enough to make use of parallelization (and don't already have it).
Does anyone have some suggestions of where to look? Or is C# just not going to have enough of that kind of thing as open source (should perhaps try C++?)
I don't know if they already use parallel tasks, but good candidates are image manipulation programs, such as paint.net or pinta.
I don't know the scope of this project (if it's just a weekly assignment or your final project), but a process that benefits from parallelization does not have to be "embarassingly parallel" as Hans' linked article describes. A problem will benefit from being parallelized if:
The solution to the problem can be expressed as the "sum" of a repetitive series of smaller operations,
The smaller operations have minimal effect on each other, and
The scale of the problem is sufficient to make the benefits of parallelization greater than the loss due to the added overhead of creating and supervising multiple worker processes.
Examples of problems that are often solved linearly, but can benefit from parallelization include:
Sorting. Some algorithms like MergeSort are atomic enough to parallelize; others like QuickSort are not.
Searching. BinarySearch cannot be parallelized, but if you're searching unordered data like a document for one or more occurrences of words, linear searches can use "divide and conquer" optimizations.
Data transformation workflows. Open a file, read its raw data, carve it up into domain fields, turn those domain fields into true domain objects, validate them, and persist them. Each data file is often totally independent of all others, and the process of transformation (which is everything between reading the file and persisting it) is often a bottleneck that benefits from having more processors thrown at it.
Constraint satisfaction problems. Given a series of business rules defining relationships and constraints of multiple variables in a problem space, find a set of those variables that meets all constraints, or determine that there are none. Common applications include transportation route scheduling and business process optimization. This is an evolving sector of computational algorithms, of relatively high academic interest, and so you may find published public-domain code of a basic CSP algorithm you can multithread. It may be described as embarassingly parallel as the best-known solution is "intelligent brute force", but nonetheless, a possible solution can be evaluated independently of others and so each can be given to a worker thread.
Processes defined as "embarassingly parallel" are generally any problems sufficiently large in scale, yet atomic and repetitive, that parallel processing is the only feasible solution. The Wiki article Hans links to mentions common applications; they usually boil down, in general, to the application of a relatively simple computation to each element of a very large domain of data.
Check out Alglib, especially the open source C# edition. It will contain a lot of matrix and array manipulations that will be nicely suitable for TPL.
Project Bouncycastle implements several encryption algorithms in C# and java. Perhaps some of them are not as parallelized as they could be.
Closed. This question is opinion-based. It is not currently accepting answers.
Want to improve this question? Update the question so it can be answered with facts and citations by editing this post.
Closed 9 years ago.
Improve this question
I wondered which unit testing framework would be a good one to get really familiar with? I know this might be a question of opinion, but I thought I'd ask anyways. I know that I will need to do it someday, so I might as well learn to use it. I know that there is quite a few out there, but which one is effective for C# development?
From this question I can see that unit testing is necessary, but personally I haven't used it. So that's why I ask this question.
Personally, I prefer the Visual Studio Unit Testing Framework, for two main reasons:
It integrates seamlessly with the IDE;
It's one less program to deploy in a dev environment.
Having said that, pretty much any unit testing framework will do the trick, the important thing is to have tests!
I would go with NUnit.
Some links:
NUnit QuickStart, NuGet Package
Don't get stuck on choosing a framework. Just pick one and start testing - they're not all that different. When you have written tests for a while, you will know what to look for, to suit your needs.
Personally, I have found xUnit, Testdriven.Net and Moq to be a very flexible set of test tools.
Also see this post: NUnit vs. MbUnit vs. MSTest vs. xUnit.net
I've decided to stick with NUnit because ReSharper provides native IDE support (which saves a lot of time). It's also supported by TeamCity in running and reporting automated tests.
I use NUnit for the testing framework and ReSharper for integrating it into VS (and everything else ReSharper does).
Use MbUnit (with Gallio), NUnit, MsTest or xUnit. You can combine several unit tests. I use NUnit for TDD
There are a few reasons for testing, thus a few testing environments. Plus, there are levels of testing, like simple, stubs, and mocks. For example, you could test behavior rather than state.
As far as function, I usually use the Visual Studio built in setup, add a reference to the NUnit dll, and change the c# annotations to be NUnit. This is because I like testing outside of Visual Studio, especially when it involves others on my team (and we didn't buy the team edition of VS yet).
Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
We don’t allow questions seeking recommendations for books, tools, software libraries, and more. You can edit the question so it can be answered with facts and citations.
Closed 6 years ago.
Improve this question
I wanted to ask whether you know about some free C# libraries (dlls) that calculate CK metrics (mainly Cyclomatic Complexity).
I would need that for a project I'm planning to do. I know that there are already some finished solutions that calculate CK metrics and display it to you in various forms, but what I would need is one that I could use from within my application. So before starting and writing one myself I first wanted to ask you.
Thanks
DrivenMetrics is a open source C# command line tool. The core functionalities are isolated from the command line console client as a library (Core project is available here).
Even if quite simple, it may fit your need: it's free, counts the the number of lines and calculates the cyclomatic complexity (number of potential code paths) of methods.
This is performed through direct analysis of the IL thanks to Mono.Cecil (the same library NDepend relies on). This allows the analysis to be performed on assemblies built from code written in C#, VB.Net,...
The project has been announced
here.
The code source is
available on github.
A packaged release is also available.
It works both on Windows and Mono.
UPDATE:
Another option would be the amazing Gendarme, a static analysis tool from the Mono project.
As a sample of usage, the code below display the cyclomatic complexity of every method in an assembly.
ModuleDefinition module = ModuleDefinition.ReadModule(fullPathToTheAssembly);
foreach (var type in module.Types)
{
foreach (var me in type.Methods)
{
if (!me.HasBody || me.IsGeneratedCode() || me.IsCompilerControlled)
continue;
var r = AvoidComplexMethodsRule.GetCyclomaticComplexity(me);
Console.WriteLine("{0}: {1}", me.ToString(), r);
}
}
The project is described here
The code source is available on github
Packaged releases are also available
It works both on Windows and Mono
I am using SourceMonitor, which is a nice freeware app that measures code complexity and other metrics for a variety of languages including C#. We drive it from the command line to produce XML output, then we use LINQ to XML to extract and sort the data we are interested in. We then use NVelocity to create HTML reports.
I know its not a managed library, but you might find it can do what you need.
There is a tool from Microsoft I am using to compute code metrics for C# assemblies.
It includes cyclo complex, maintainability index and more.
Details here:
http://blogs.msdn.com/b/camerons/archive/2011/01/28/code-metrics-from-the-command-line.aspx
Download here:
http://www.microsoft.com/en-us/download/details.aspx?id=9422
It isn't free but I've had good experiences with NCover for this sort of thing. They also integrate pretty well with a lot of CI tools out there.
With 82 code metrics supported NDepend is the code metrics Roll's Royce tooling for .NET developers (however it is a commercial tool).
Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
We don’t allow questions seeking recommendations for books, tools, software libraries, and more. You can edit the question so it can be answered with facts and citations.
Closed 3 years ago.
Improve this question
I am getting back into a bit more .NET after a few-years of not using it full-time and am wondering what the good unit testing packages are these days.
I'm familiar with NUnit (a few years ago) and have played briefly around with IronRuby, with the goal of getting something like RSpec going, but I don't know much beyond that.
I realize I could google for this and call it a day, but I believe I'm likely to get a better and more informed response from asking a question here :-)
Suggestions?
There are so many it's crazy. Crazy good, I guess.
For the conservative types (me), NUnit is still available and still more than capable.
For the Microsoft-types, MSTest is adequate, but it is slow and clunky compared to NUnit. It also lacks code coverage without paying the big bucks for the pricey versions of Visual Studio.
There's also MbUnit. It's like NUnit, but it has nifty features like RowTest (run the same test with different parameters) and Rollback (put the database back like you found it after a test).
And finally, xUnit.net is the trendy option with some attitude.
Oh, and TestDriven.NET will give you IDE integration for both NUnit and MbUnit.
I'm sure they're all just fine. I'd steer away from MSTest though, unless you just enjoy the convenience of having everything in one IDE out of the box.
Scott Hanselman has a podcast on this very topic.
Stick to NUnit. Don't go anywhere near MSTest.
NUnit + ReSharper is an absolute joy to work with.
We use NUnit and MbUnit here. We use TestDriven.NET to run the unit tests from within Visual Studio. We use the excellent, highly recommended RhinoMocks as a mock framework.
I used to use NUnit, but now tend to use MbUnit, for two key features:
1. The RowTest feature allows you to easily run the same test on different sets of parameters, which is important if you really want thorough coverage.
2. The Rollback feature allows you to run tests against your database while rolling back changes after every test, keeping your database in exactly the same state every time. And it's as easy as adding the [Rollback] attribute.
Another nice aspect of MbUnit is that its syntax is nearly identical to NUnit, so if you have a whole test bed already in place under NUnit, you can just switch out the references without the need to change any (very much?) code.
xUnit.net looks like it provides a slightly different approach to NUnit, MbUnit, and MSTest, which is interesting.
In my search for an RSpec-like solution (because I love the RSpec), I also came across NSpec, which looks a bit wordy, but combined with the NSpec Extensions addon to use C# 3 extension methods, it looks pretty nice.
I use the following:
TestDriven.NET - Unit testing add on for Visual Studio
Typemock Isolator- Mocking framework for .NET unit testing
NUnit - An open source unit testing framework that is in C#.
You might find it interesting that Gallio v3.1 now supports RSpec via IronRuby.
I like TestDriven.NET (even though I use ReSharper) and I'm pretty happy with XUnit.net. It uses Facts instead of Tests which many people dislike but I like the difference in terminology. It's useful to think of a collection of automatically provable Facts about your software and see which ones you violate when you make a change.
Be aware that Visual Studio 2008 Professional (and above) now comes with integrated Unit Testing (it used to be available only with the Team System Editions) and may be suitable for your needs.
I used to use NUnit, but I switched to MbUnit since it has more features.
I love RowTest. It lets you parametrize your tests. NUnit does have a little bit better tool support though. I am using ReSharper to run MbUnit tests. I've had problems with TestDriven.NET running my SetUp methods for MbUnit.
NUnit, MSTest, etc. all do pretty much the same thing. However, I find NMock indispensable.
NMock or any mocking package is not unit testing, but it makes it so much easier to do unit testing that it might as well be.
I like MbUnit, er, Gallio. Most importantly to me is having good tools support inside Visual Studio. For that I use Resharper, which has an MbUnit test runner. A lot of folks seem to like TestDriven.NET as their test runner as well.