I am trying to modify the PartCover source code to exclude coverage by method. However,it looks like the main logic is in the c++ code. Since it is not possible to step into the cpp code while debugging,can someone please guide me as to which files I would need to modify? I am thinking it should be rules.cpp and instrumentator.cpp...and some refactoring needed in other .cpp .h and .cs files due to changes made in these. But If I am wrong, or if there are other places that I should also be looking at, please let me know. Any other hint to proceed would also be appreciated.
Thanks,
Thanks for your reply.
However, uncommenting the DebugBreak is causing the nunit-console-86.exe to stop working. I changed the NUnit version to 2.5.7 to match it with the version of nunit-framework.dll inside the PartCover bin folder, but the problem still exists. Any idea what could be causing this?
We have our own console app that runs coverage check method wise. It makes sure if any new method is added, or code in existing methods refactored, the coverage still should be at least more than our decided percentage. Sometimes there are methods for which testing cannot be done completely for whatsoever reason. For those, it doesn't make sense to exclude the entire class.
The files you have mentioned are probably the best places in the C++ code to apply your extra filter. I assume you have a way of extending the syntax currently used for include and exclude filters of modules and classes.
You can debug the code if you uncomment the DebugBreak in CorProfiler::Initialize (when you .NET process runs and the profiler is loaded this will allow you to attach a C++ debugger to the profiler)
May I ask why you need to exclude specific methods? I can see the need to exclude classes i.e. Test Classes and the like but not specific methods, this seems like something that could be easier done if necessary be just ignoring the results in any reports.
Related
I want to intercept ClassLoader's loadClass method. In order to show the process of loading class by ClassLoader. But I don't know the working principle of aspectj. It can modify the source code of the JDK?
You could just use a debugger and step through the process in order to understand it.
AspectJ can weave aspects into existing class files during compilation (CTW, compile-time weaving) or during class-loading (LTW, load-time weaving).
LTW does not work for JDK classes because those classes are always loaded before the weaving agent. So you have a bootstrapping problem there.
What you can do, however, is to apply CTW to the class files in e.g. rt.jar from your JRE/JDK distribution, zip the woven class files into another JAR and replace the original one with it. Then if you start the JVM with aspectjrt.jar on the boot classpath, you see the aspects in action. I have done that before and it works. But really, this is not what AspectJ was designed for. But you asked, so I told you. It is a very advanced topic though, and I doubt that it is the road you should take as a complete AspectJ greenhorn - no offense meant.
Update: Because I have been asked this question so often, I created a little demo project showing how to weave aspects into the JRE/JDK. I still do not think it makes sense to use it under normal circumstances, but what the heck: Why do people climb the Mount Everest? Because it exists. ;-)
One of the requirements for this project is that it must be able to launch w/out admin. It is a massive project, so I can't really show you the source and a meaningful and helpful way
I've gone to some people for help, and they suggest that I look throughout my project for any times I write files. However, I can't think of anywhere else I still do this, and yet the exe will only run in admin mode. If you try and run it in non-admin mode, it crashes.
I understand that it's difficult to debug if you can't see project, but the project is hundreds of files. Mainly, I'm looking for advice on the kinds of things that would cause a program to crash in not admin mode but run perfectly fine in admin mode
Just as the many people suggested, the issue was opening a file with read/write privileges. Even though we were only reading from the file, we opened the file as an fstream instead of an ifstream.
I missed it because the problem was hiding in some string utils functions that were written by another team member who is no longer with the team. Pretty much no one was using those string functions or was aware they existed.
Thanks for yours guys' suggestions regardless!
For starters, I don't think you can run and install vcredist_x86.exe without admin privileges.
Other than that, in general to not ask for UAC, I think you need to setup the PrivilegesRequired properly.
EDIT: To work-around the need to install vcredist you could use static runtime linking. However, that has some disadvantages as well (for example, memory allocation/deallocation must then be always done in the same memory context, i.e. the same dll/executable - which is always the best policy anyway).
I have question related to creating test methods in my coded UI test.
Is it possible to create like rules or like an if else statement tree that would execute certain test methods to run when certain things happening or when i'm on a certain counter?.
I don't know if this is the correct way to do this. I was going to do it in a 1 huge block of code but i dont really like the direction that is going in, since the application i'm testing has to account for different paths.
I want to create and have test methods run based on these if else statements code blocks.
If anyone has done this any help would be greatly appreciated. Thanks
I think you want your tests to be as small as possible and test only one thing.
For multiple reasons you want to test in isolation and not make tests depended on each other. What you are trying todo sounds very unmaintainable on the long run.
Also when a single test steps fails, you might need to run a long test to see the actual fail, making debuging harder and slower.
I would follow the AAA pattern in your tests to guide you
Arrange: Setup the state of the application including data
Act: The action you want to test. (e.g fill in a form and submit)
Assert: Verify the action was correct by checking one thing
It is possible to group tests and run only a subset, for details see: https://msdn.microsoft.com/en-us/library/dd286683.aspx
I can't work out how to get unit testing to work with Boost and Eclipse.
I get lots of different errors depending on where I put the source files.
Where are the tests supposed to go? (ie should I create a test folder in root, in src, no folder at all or what)
Do I need to specify something somewhere if I don't intend to have a main(), and just lots of tests?
I'm really confused, and I know I'm being quite lite on the details - hopefully you can show me the proper way to do Unit Testing with Boost in Eclipse rather than whatever I'm currently doing.
Compile your application in eclipse first normal without unit tests.
After that create a new Project and reference it to the former Project with your application.
Than you create a main.cpp and insert your unit tests there.
You should be able to use the other projects classes from the new Project. Therefore, you are able to Instantiate Objects and do your asserts or whatever you like. If you have any further questions, please post your actual error and provide a screen-shot of your current structure.
I mainly develop in native C++ on Windows using Visual Studio.
A lot of times, I find myself creating a new function/class or whatever, and I just want to test that piece of logic I just wrote, quickly.
A lot of times, I have to run the entire application, which sometimes could take a while since there are many connected parts.
Is there some sort of tool that will allow me to test that new piece of code quickly without having to run the whole application?
i.e.
Say I have a project with about 1000 files, and I'm adding a new class called Adder. Adder has a method Add( int, int );
I just want the IDE/tool to allow me to test just the Adder class (without me having to create a new project and write a dummy main.cpp) by allowing me to specify the value of the inputs going into Adder object. Likewise, it would be nice if it would allow me to specify the expected output from the tested object.
What would be even cooler is if the IDE/tool would then "record" these sets of inputs/expected output, and automatically create unit tester class based on them. If I added more input/output sets, it would keep building a history of input/outputs.
Or how about this: what if I started the actual application, feed some real data to it, and have the IDE/tool capture the complete inputs going into the unit being tested. That way, I can quickly restart my testing if I found some bugs in my program or I want to change its interface a bit. I think this feature would be so neat, and can help developer quickly test / modify their code.
Am I talking about mock object / unit testing that already exists?
Sidenote: it would be cool if Visual Studio debugger has a "replay" technology where user can step back to find what went wrong. Such debugger already exists here: http://www.totalviewtech.com/
It's very easy to get started with static unit testing in C++ - three lines of code.
VS is a bit poor in that you have to go through wizards to make a project to build and run the tests, so if you have a thousand classes you'd need a thousand projects. So for large projects on VS I've tended to organised the project into a few DLLs for independent building and testing rather than monolithic ones.
An alternative to static tests more similar to your 'poke and dribble' script could be done in python, using swig to bind your code to the interpreter, and python's doc tests . I haven't used both together myself. Again, you'd need a separate target to build the python binding, and another to run the tests, rather than it being just a simple 'run this class' button.
I would go with Boost.Test (see tutorial here)).
The idea would be to add a new configuration to your project, which would exclude from build all unnecessary cpp files. You would just have to add .cpp files to describe the tests you want to pass.
I am no expert in this area but i have used this technique in the past and it works !
I think you are talking about unit testing and mock objects. Here are couple of C++ mock object libraries that might be useful :-
googlemock which only works with googletest
mockpp
You are essentially asking how can I test one function instead of the whole application. That is what unit-testing is, and you will find many questions about unit-testing C++ on SO.