|
I've noted with interest that there seems to be a lack of open source tools for .NET test coverage analysis. I'm pretty comfortable with .NET, but off the top of my head, I can't figure out how someone could do it without making their own version of the runtime or tampering with the IL emitted when code is compiled (which sounds like either great resume material, insanity, or possibly both).
I'm just kind of curious, but I'm not sure even how this sort of thing is typically done.
|
|
|
|
|
Easier than tampering with the IL is tampering with the source code. I used to do formal unit testing and I don't know if it's a formal term or not but we called it "instrumenting a file" and it's a bit of tedium that automated processes are made for. The trick is to modify the source without actually changing the control flow of the code. Take the following function:
private void MyMethod()
{
int x = SomeFunction();
int y = SomeOtherFunction();
if (x > y)
{
}
else
{
}
} There are 5 bits of code you need to ensure are executed, so for each place insert a boolean:
static bool flag1 = false;
static bool flag2 = false;
static bool flag3 = false;
static bool flag4 = false;
static bool flag5 = false;
private void MyMethod()
{
flag1 = true;
int x = SomeFunction();
flag2 = true;
int y = SomeOtherFunction();
flag3 = true;
if (x > y)
{
flag4 = true;
}
else
{
flag5 = true;
}
} Then you can run your test cases and check the value of your bools to make sure that all of your code was executed. Note that the control flow of the code hasn't changed, we've just added stuff to verify that all bits are executed. The difficulty comes in when you start taking into account the endless variations of source code. For example:
private void MyMethod()
{
int x = SomeFunction();
int y = SomeOtherFunction();
if (x > y)
{
}
} looks easier, but you still need to insert the else to the if when you instrument that method to prove that the if statement can be failed. If the if can't be failed then it's unnecessary (dead code) and shouldn't be there.
The biggest PITA to instrument (and test) is full MCDC coverage (google it). Take the following sample:
private void MyMethod(bool a, bool b)
{
if (a || b)
{
}
} There's a multi-conditional if statement there, and you need to prove that both conditions are necessary. Why? Well, suppose hypothetically that a is always true . Then the statement will always evaluate to true and there's no point in checking either a or b . The same thing happens if b is always true, so you need to instrument that in such a way to prove that both a and b can be false independently of each other. To verify full coverage that one statement turns into something like this:
static bool flag1 = false;
static bool flag2 = false;
static bool flag3 = false;
static bool flag4 = false;
private void MyMethod(bool a, bool b)
{
flag1 = true;
if (a && !b)
{
flag2 = true;
}
else
{
if (b)
{
flag3 = true;
}
else
{
flag4 = true;
}
}
} and that 's just a simple multi-conditioned statement! Try figuring out how to break this down:
if (a || ((b && c) || d) || (x > 2))
{
} Hopefully you either don't care about such things or you can afford to buy a tool to do this for you. Trust me, it will drive you crazy.
|
|
|
|
|
The .NET Framework has a profiling API available for just such a thing. Here's a nice introductory article.[^].
"we must lose precision to make significant statements about complex systems."
-deKorvin on uncertainty
|
|
|
|
|
The CLR profiler allows you to rewrite IL at JIT time. That would be one place to put instrumentation code to track what code is getting executed.
|
|
|
|
|
I have a set of objects that I want to do some processing on prior to serializing and after deserializing,using wcf for coms.
The code is included below. I understand that I should change OnDeserializing to OnDeserialized, and have, but neither get called.
If I put a break in the OnSerializing method, the debugger stops there. If I put a break in the OnDeserializing method, the debugger never stops there. It is also clear from the errors I am getting that the re-hydration has not happened.
I am following the same pattern for both the pre and post calls. The compiler is happy with them, and they look like they match the patterns in the online doc.
Any ideas? This is also posted on MSDN with no help forthcoming.
hury Plz snd code and dollars
TIA
[OnSerializing ()]
internal void OnSerializingMethod(StreamingContext context)
{
long temp = 0;
if (context.State != StreamingContextStates .Clone)
{
Dehydrate (null , ref temp);
}
}
[OnDeserializing ()]
internal void OnDeserializingMethod(StreamingContext context)
{
if (context.State != StreamingContextStates .Clone)
{
Rehydrate (0);
}
}
Silver member by constant and unflinching longevity.
|
|
|
|
|
Because of WCF generate proxy for DataContract with [System.Diagnostics.DebuggerStepThroughAttribute()].
|
|
|
|
|
Hi,
I have developed a smart client desktop application using SCSF.
It has an MDI and MDI child forms opens over it(It is similar to windows menu based application using MDI) .
The problem is that the MDI child forms (i.e. the views) take a few seconds to open and load.
Is there any way of minimising the time it takes.
The forms are having simple text boxes and labels and grids(which has two columns and is not populated during load)
I call a webservice at form load and have tried to comment the service call; Even then it takes the same time so I have ruled out the possibility of service delay.
Nothing else is done at the form load except the form is rendered
All MDI child forms(views) are taking the same time.
The application is stand alone not run remotely or checks for any updates on any server.
I dont have knowledge of SCSF internals, and how SCSF does all the handling of smart parts etc.
May be it might be tuned up to load the views faster or there is some way to make the CAB work faster which I am unaware of.
Could not find the forum related to SCSF so posting it here, please suggest in case you have knowledge of SCSF message board in code project.
Thanks in advance.
Sakshi
|
|
|
|
|
SCSF uses reflection very heavily. Because of this reason performance is hit when trying to do what would seem the simplest of things. It is a very heavy framework and unless you really need it and are concerned about performance I would suggest an alternative.
|
|
|
|
|
Dear all, upon developing data entry project I've faced a problem and I still can't figure out the solution.
Simplifying the matter, lets say that the the user enters the ID value and should get the decription in another column (DataGridViewTextbox) in the same datagridview. The description column should get updated immediately after the value of the ID column is changed.
The scenario is very close to classical master/detail form except that the detail should be displayed into the same control.
I had particullar success when bound the datagridview control to dataset relation, but the form didn't work well when inserting new rows.
Can you provide me with brief advice or a link?
Kind regards,
|
|
|
|
|
|
Thank you very much for your reply!
I will take a look.
Anyway I will try to clarify myself by pseudo-code.
Consider DB with two tables:
table "payments" with the following structure:
"p_id" int,
"price" int,
"empl_id" int
and "employees":
"empl_id" int,
"empl_name" varchar /* this I want to get later */
It is not difficult to bind the DataGridView control to the "payments" table.
In the form I define the following columns (binding them to corresponding columns in data source):
datagridview.Columns("pay_id").DataPropertyName = "payments"."p_id"
datagridview.Columns("price").DataPropertyName = "payments"."price"
datagridview.Columns("empl_id").DataPropertyName = "payments"."empl_id"
And here is it, I want to have a column which displays the employee's name taking it from table "employees". Something like:
datagridview.Columns("empl_name").DataPropertyName = "employees"."empl_name"
This column should refresh every time the user changes the value of datagridview.Columns("empl_id") providing him with the name of the employee.
But there is no way (at least I don't know how) to define another data source for DataGridViewTextBox column. May be I need to populate manually the cell with the employee's name fetching it from dataset relation.
Previously I hadn't used .NET for data entry forms which is my primary fields so I am not very certain about its classes and their properties.
Thanks and regards,
|
|
|
|
|
you can use DataGridViewComboBox column instead of DataGridViewTextBoxColumn to show employee's name.
Example:
datagridview.Columns("empl_name").DisplayMember="empl_name"
datagridview.Columns("empl_name").ValueMember ="empl_id"
datagridview.Columns("empl_name").DataSource ="employees"
datagridview.Columns("empl_name").DataPropertyName="payments"."p_id"
datagridview.Columns("empl_name").DisplayStyle=Nothing
|
|
|
|
|
Hi,
how to pass a "IS NOT NULL" to an OleDbParameter?
I know how to do "IS NULL":
parameter = new OleDbParameter(myField, Convert.DBNull);
Any Help would be great...
Thank's
:k:
|
|
|
|
|
|
You can pass in an actual Null value for the parameter using your code, but this doesn't mean you're passing "IS NULL" or "IS NOT NULL". These aren't values, they're conditions, presumably your stored procedure or query would then use IS NULL or IS NOT NULL to check whether or not the value you passed in was or was not a Null.
|
|
|
|
|
How do .net framework relates to ajax technology.
|
|
|
|
|
sapna sangole wrote: How do .net framework relates to ajax technology.
They are both code.
Please clarify what you are asking - are you asking how do you implement AJAX in the .NET framework, or are you asking what AJAX is, and how it differs from the .NET framework?
"WPF has many lovers. It's a veritable porn star!" - Josh Smith As Braveheart once said, "You can take our freedom but you'll never take our Hobnobs!" - Martin Hughes.
My blog | My articles | MoXAML PowerToys | Onyx
|
|
|
|
|
You can use AJAX with .Net framework in 2 ways
1. Use asynchronous Javascript method call to find server function and write everything by you only by you.
2. Or Install free Microsoft AJAX Framework and take advantage of AJAX Control Toolkit.
Education is not a way to escape poverty — it is a way of fighting it.
|
|
|
|
|
Hi Guys,
I've got a little wrapper class that exposes some registry properties in my code. This works and passes the unit test for writing and reading the value and comparing the result. However, when i look in the registry, there's no section for the values i am manipulating.
public static void SetGroupRegInfo(string group, string key, string value)
{
RegistryKey rkApp = Registry.LocalMachine.CreateSubKey(
REGISTRY_MICA_GROUPS + "\\" + group,
RegistryKeyPermissionCheck.ReadWriteSubTree);
try
{
rkApp.SetValue(key, value);
}
finally
{
rkApp.Close();
}
}
public static string GetGroupRegInfo(string group, string key)
{
RegistryKey rkApp = Registry.LocalMachine.OpenSubKey(
REGISTRY_MICA_GROUPS + "\\" + group,
RegistryKeyPermissionCheck.ReadSubTree,
RegistryRights.QueryValues);
if (rkApp == null)
return null;
try
{
return (string)rkApp.GetValue(key);
}
finally
{
rkApp.Close();
}
}
The base registry entries are created correctly by the application installer, but these values just don't seem to appear.
Any thoughts?
Regards
Tris
-------------------------------
Carrier Bags - 21st Century Tumbleweed.
|
|
|
|
|
I find your post confusing. You say the Unit Tests pass but we have no idea what is being tested. You say "it works" but the value is not in the registry so I have no idea what "it works" means because to me if the value is not written to the registry then I would say it is NOT working.
|
|
|
|
|
can't stay away for more than 8 minutes, can you?
Luc Pattyn [Forum Guidelines] [My Articles]
The quality and detail of your question reflects on the effectiveness of the help you are likely to get.
Show formatted code inside PRE tags, and give clear symptoms when describing a problem.
|
|
|
|
|
Luc Pattyn wrote: can't stay away for more than 8 minutes, can you?
Hey Luc,
See here[^]
and here[^]
So long dude.
|
|
|
|
|
Exactly, that[^] and your above message are 8 minutes apart.
Luc Pattyn [Forum Guidelines] [My Articles]
The quality and detail of your question reflects on the effectiveness of the help you are likely to get.
Show formatted code inside PRE tags, and give clear symptoms when describing a problem.
|
|
|
|
|
Luc Pattyn wrote: and your above message are 8 minutes apart.
That time is the original post, I modified it twice, see where I say "I just changed my mind".
|
|
|
|
|
I see. I never mind the "modified at..." message that gets added automatically, it uses Bujumbura local time or something similar, doesn't tell me much.
In the mean time, you're still here. Which is great.
BTW: if and when the new be-really-kind rules would really cripple you, you can always put a leaded answer in one of the soapboxes/back rooms, and just reply with a link to it.
Luc Pattyn [Forum Guidelines] [My Articles]
The quality and detail of your question reflects on the effectiveness of the help you are likely to get.
Show formatted code inside PRE tags, and give clear symptoms when describing a problem.
|
|
|
|