Best practice for unit testing? / C # InternalsVisibleTo () for VBNET 2.0 during testing?

I am creating an Active Directory wrapper in VBNET 2.0 (I cannot use .NET later), in which I have the following:

  • Iutilisateur
  • Igroupe
  • IUniteOrganisation

These interfaces are implemented in inner classes (Friend in VBNET), so I want to implement a facade to initiate each of the interfaces with their inner classes. This will allow the architecture to increase flexibility, etc.

Now I want to test these classes (Utilisateur, Groupe, UniteOrganisation) in another project as part of the same solution. However, these classes are internal. I would like to be able to create them without going through my facade, but only for these tests, nothing more.

Here is a code snippet to illustrate it:

public static class DirectoryFacade { public static IGroupe CreerGroupe() { return new Groupe(); } } // Then in code, I would write something alike: public partial class MainForm : Form { public MainForm() { IGroupe g = DirectoryFacade.CreerGroupe(); // Doing stuff with instance here... } } // My sample interface: public interface IGroupe { string Domaine { get; set; } IList<IUtilisateur> Membres { get; } } internal class Groupe : IGroupe { private IList<IUtilisateur> _membres; internal Groupe() { _membres = new List<IUtilisateur>(); } public string Domaine { get; set; } public IList<IUtilisateur> Membres { get { return _membres; } } } 

I recently heard about the InternalsVisibleTo () attribute. I was wondering if it is available in VBNET 2.0 / VS2005 so that I can access the assmebly inner classes for my tests? Otherwise, how could I achieve this?

EDIT Is this a good testing practice like me?

+4
source share
1 answer

Yes, the InternalsVisibleTo attribute is available on vb.net and works with types of Others.

+5
source

Source: https://habr.com/ru/post/1309668/


All Articles