Добавил:
Опубликованный материал нарушает ваши авторские права? Сообщите нам.
Вуз: Предмет: Файл:
strauss_d_getting_started_with_visual_studio_2022_learning_a.pdf
Скачиваний:
123
Добавлен:
26.06.2023
Размер:
17.04 Mб
Скачать

Chapter 4 Unit Testing

Focus IntelliTest Code Exploration

Sometimes, IntelliTest needs a bit of help focusing code exploration. This can happen if you have an Interface as a parameter to a method and more than one class implements that Interface. Consider the code in Listing 4-14.

Listing 4-14.  Focusing Code Exploration

public class ShipFreight

{

public void CalculateFreightCosts(IShippable box)

{

}

}

class Crate : IShippable

{

public bool CustomsCleared { get; }

}

class Package : IShippable

{

public bool CustomsCleared { get; }

}

public interface IShippable

{

bool CustomsCleared { get; }

}

If you ran IntelliTest on the CalculateFreightCosts method, then you will receive warnings as can be seen in Figure 4-20.

239

Chapter 4 Unit Testing

Figure 4-20.  Focus code exploration

You can tell IntelliTest which class to use to test the interface. Assume that I want to use the Package class to test the Interface. Now, just select the second warning and click the Fix button on the menu as seen in Figure 4-21.

Figure 4-21.  Tell IntelliTest which class to use

IntelliTest now updates the PexAssemblyInfo.cs file by adding [assembly: PexUseType(typeof(Package))] to the end of the file to tell IntelliTest which class to use. Running IntelliTest again results in no more warnings being displayed.

240