Has branch coverage been implemented?

Has branch coverage been implemented?

Hi all,

I just want to know if branch coverage feature has been implemented in the latest version of NCover.Also,I would like to know if path coverage is also implemented.

Thank you.


Re: Has branch coverage been implemented?

I believe the answer to both is no - NCover 1.5.7 due shortly does not have any new types of coverage added (mainly a load of bug fixes).


Re: Has branch coverage been implemented?

Not yet.  It's on my wishlist.


Re: No coverage results for unused classes

I have almost the opposite, but I feel it is related. We use Mbunit. We have a test using reflection to find the functions to test. This gives nothing in the ncover.xml, no lines not tested, but also nothing else. This test tests the class completly, but is not picked up by ncover. When I add an ignored test, I have 100 %. 

Very strange.
Yves Hanoulle

this is the exception test :

using System;

using System.Collections.Generic;

using System.Text;

using MbUnit.Framework;

using System.Reflection;

using System.Runtime.Serialization;

using System.Runtime.Serialization.Formatters.Binary;

using System.IO;

namespace Mesware.Common.Exceptions.SmokeTests

{

[TestFixture]

public class ExceptionsTest

{

protected virtual string[] GetTestedAssemblyNames()

{

AssemblyName asmName = Assembly.GetExecutingAssembly().GetName();

string subString = ".Smoketests";

int i = asmName.Name.IndexOf(subString);

if (i==-1)

return new string[0];

string name = asmName.Name.Remove(i, subString.Length);

return new string[] {name};

}

private Assembly[] GetTestedAssemblies()

{

List<Assembly> result = new List<Assembly>();

Assembly[] loadedAssemblies = AppDomain.CurrentDomain.GetAssemblies();

foreach(string name in GetTestedAssemblyNames()) {

foreach(Assembly asm in loadedAssemblies) {

if (asm.GetName().Name==name) {

result.Add(asm);

break;

}

}

}

return result.ToArray();

}

protected virtual void TestException(Type type, StringBuilder errors)

{

if (!type.IsDefined(typeof(SerializableAttribute), false)) {

errors.AppendLine(string.Format(

"Exception type '{0}' is not marked with Serializable attribute.", type));

}

ConstructorInfo defaultConstructorInfo;

ConstructorInfo info;

// default constructor

info = defaultConstructorInfo = type.GetConstructor(

BindingFlags.DeclaredOnly | BindingFlags.Instance | BindingFlags.Public,

null,

Type.EmptyTypes,

null);

if (info==null) {

errors.AppendLine(string.Format(

"Exception type '{0}' doesn't contain default constructor.", type));

}

else {

try {

info.Invoke(null);

}

catch(Exception ex) {

errors.AppendLine(string.Format(

"Exception was thrown when the '{0}' default constructor was called: '{1}'.",

type, ex));

}

}

// constructor with string argument

info = type.GetConstructor(

BindingFlags.DeclaredOnly | BindingFlags.Instance | BindingFlags.Public,

null,

new Type[] {typeof(string)},

null);

if (info==null) {

errors.AppendLine(string.Format(

"Exception type '{0}' doesn't contain a constructor with one string argument",

type));

}

else {

try {

info.Invoke(new object[] {Guid.NewGuid().ToString()});

}

catch(Exception ex) {

errors.AppendLine(string.Format(

"Exception was thrown when the '{0}' constructor with one"+

" string argument was called: '{1}'.",

type, ex));

}

}

// constructor with string and exception arguments

info = type.GetConstructor(

BindingFlags.DeclaredOnly | BindingFlags.Instance | BindingFlags.Public,

null,

new Type[] {typeof(string), typeof(Exception)},

null);

if (info==null) {

errors.AppendLine(string.Format(

"Exception type '{0}' doesn't contain a constructor having arguments"+

" with string and Exception types", type));

}

else {

try {

info.Invoke(new object[] {Guid.NewGuid().ToString(), new Exception()});

}

catch(Exception ex) {

errors.AppendLine(string.Format(

"Exception was thrown when the '{0}' constructor having arguments"+

" with string and Exception types was called: '{1}'.",

type, ex));

}

}

// deserialization constructor

info = type.GetConstructor(

BindingFlags.DeclaredOnly | BindingFlags.Instance |

BindingFlags.Public | BindingFlags.NonPublic,

null,

new Type[] {typeof(SerializationInfo), typeof(StreamingContext)},

null);

if (info==null) {

errors.AppendLine(string.Format(

"Exception type '{0}' doesn't contain a deserialization constructor", type));

}

else if (defaultConstructorInfo!=null) {

try {

ISerializable o = (ISerializable)defaultConstructorInfo.Invoke(null);

MemoryStream ms = new MemoryStream();

BinaryFormatter formatter = new BinaryFormatter();

formatter.Serialize(ms, o);

ms.Seek(0, SeekOrigin.Begin);

formatter.Deserialize(ms);

}

catch(Exception ex) {

errors.AppendLine(string.Format(

"Exception was thrown when trying to deserialize '{0}' instance: '{1}'.",

type, ex));

}

}

}

[Test]

public void TestExceptions()

{

// Force loading of references

foreach(AssemblyName name in

Assembly.GetExecutingAssembly().GetReferencedAssemblies()) {

AppDomain.CurrentDomain.Load(name);

}

StringBuilder errors = new StringBuilder();

Assembly[] asms = GetTestedAssemblies();

foreach(Assembly asm in asms) {

foreach(Type t in asm.GetTypes()) {

if (typeof(Exception).IsAssignableFrom(t)) {

TestException(t, errors);

}

}

}

if (errors.Length>0) {

Assert.Fail(errors.ToString());

}

}

}

}