Condividi tramite


Metodo WebTestPlugin.PreWebTest

Se sottoposto a override in una classe derivata, rappresenta il metodo che gestirà l'evento associato all'inizio del test delle prestazioni Web.

Spazio dei nomi:  Microsoft.VisualStudio.TestTools.WebTesting
Assembly:  Microsoft.VisualStudio.QualityTools.WebTestFramework (in Microsoft.VisualStudio.QualityTools.WebTestFramework.dll)

Sintassi

'Dichiarazione
Public Overridable Sub PreWebTest ( _
    sender As Object, _
    e As PreWebTestEventArgs _
)
public virtual void PreWebTest(
    Object sender,
    PreWebTestEventArgs e
)
public:
virtual void PreWebTest(
    Object^ sender, 
    PreWebTestEventArgs^ e
)
abstract PreWebTest : 
        sender:Object * 
        e:PreWebTestEventArgs -> unit 
override PreWebTest : 
        sender:Object * 
        e:PreWebTestEventArgs -> unit 
public function PreWebTest(
    sender : Object, 
    e : PreWebTestEventArgs
)

Parametri

Note

Fornisce un punto di ingresso di esecuzione del codice all'inizio di un test delle prestazioni Web.

Esempi

Nell'esempio seguente viene illustrato un plug-in di test delle prestazioni Web che aggiunge un numero casuale al contesto prima dell'esecuzione del test delle prestazioni Web utilizzando il metodo PreWebTest. Analogamente è possibile eseguire l'override di PostWebTest ed eseguire un'azione dopo l'esecuzione del test delle prestazioni Web. È ad esempio possibile scrivere in un file di log il tempo necessario per completare il test delle prestazioni Web e il numero di richieste emesse durante tale test.

using System;
using Microsoft.VisualStudio.TestTools.WebTesting;
using System.Windows.Forms;

namespace WebTestPluginNamespace
{
    public class MyWebTestPlugin : WebTestPlugin
    {
        public static string NewRandomNumberString(int size)
        {
            byte[] buffer = new byte[size];
            // Seed using system time
            Random random = new Random(unchecked((int)DateTime.Now.Ticks));

            random.NextBytes(buffer);
            return BitConverter.ToInt32(buffer, 0).ToString();
        }

        public override void PreWebTest(object sender, PreWebTestEventArgs e)
        {
            e.WebTest.Context["RandNum"] = NewRandomNumberString(4);
        }
        
    }
}

Sicurezza di .NET Framework

Vedere anche

Riferimenti

WebTestPlugin Classe

Spazio dei nomi Microsoft.VisualStudio.TestTools.WebTesting