Come testare metodi asincroni usando nunit?come testare metodi asincroni usando nunit
risposta
Se si dispone della versione 5 di .NET del compilatore C#, è possibile utilizzare nuove asincrone e attendere le parole chiave. allegare il collegamento: http://simoneb.github.io/blog/2013/01/19/async-support-in-nunit/
Se è possibile utilizzare la chiusura con la funzione lambda anonima, utilizzando la sincronizzazione dei thread.
ad esempio)
[TestFixture]
class SomeTests
{
[Test]
public void AsyncTest()
{
var autoEvent = new AutoResetEvent(false); // initialize to false
var Some = new Some();
Some.AsyncFunction(e =>
{
Assert.True(e.Result);
autoEvent.Set(); // event set
});
autoEvent.WaitOne(); // wait until event set
}
}
Si potrebbe utilizzare NUnits Delayed Constraint
[TestFixture]
class SomeTests
{
[Test]
public void AsyncTest()
{
var result = false;
var Some = new Some();
Some.AsyncFunction(e =>
{
result = e.Result;
});
Assert.That(() => result, Is.True.After(1).Minutes.PollEvery(500).MilliSeconds);
}
}
Questo esempio è per NUnit 3.6, ma le versioni precedenti di supporto anche ritardato Constraint, ma occhiata in su come la sintassi è diversa.
StackOverflow non dovrebbe consentire voti bassi senza una spiegazione. Per favore, spiegati quando down, in modo che ci aiuti tutti a imparare. – Daryn
- 1. metodi asincroni restituiscono null
- 2. Metodi asincroni in NSOperation
- 3. XmlWriter metodi asincroni
- 4. Interfacce e metodi asincroni
- 5. Devo testare i metodi privati usando RSpec?
- 6. Come funzionano i metodi asincroni in C#?
- 7. metodi asincroni in istruzione using
- 8. Come posso testare metodi void?
- 9. Come scrivere correttamente Parallel.Per metodi asincroni
- 10. Come documentare le eccezioni dei metodi asincroni?
- 11. Prova i metodi privati e le classi interne con NUnit?
- 12. Test asincroni in VSUTF, NUnit, xUnit.NET, MbUnit vs SUTF?
- 13. I metodi asincroni dell'applicazione Mvc sono sospesi
- 14. Copertura del codice per i metodi asincroni
- 15. Come posso testare i miei metodi meteorologici?
- 16. Come posso testare l'unità Log4j usando JMockIt?
- 17. Come si chiamano i metodi asincroni in asp.net C# 4.0?
- 18. Chiamate di metodi asincroni con Ruby come con Ajax
- 19. Qual è il tipo VoidTaskResult in relazione ai metodi asincroni?
- 20. Web di Azure - Posso utilizzare i metodi asincroni?
- 21. Come testare il playbook Ansible usando Docker
- 22. Come testare un frammento usando Espresso
- 23. Come testare il servizio Grails usando Spock?
- 24. Come testare un ModelBinder personalizzato usando Moq?
- 25. Come testare Java-Spark usando JUNit?
- 26. Come testare i modelli Symfony2 usando PHPUnit
- 27. Come posso testare l'autenticazione HMAC usando Dropwizard?
- 28. Come testare l'autenticazione usando REST Framework JWT?
- 29. Perché i metodi asincroni non aspettati non generano eccezioni?
- 30. Objective-C - In attesa di due metodi asincroni da completare
Che problema stai avendo? Li hai appena testati; e controlla la cosa che stanno facendo. Voglio dire, non importa cosa avrai bisogno di aspettare. È solo questione di vedere se riesci a farti avvertire, quindi non hai bisogno di sondare. Può o potrebbe non essere possibile. –
Vicino al duplicato di ["Come posso testare un metodo asincrono con NUnit, eventualmente con un altro framework?"] (Http://stackoverflow.com/questions/12191831/how-do-i-test-an-async-method- con-nunit-eventualmente-con-un-altro-quadro) – chwarr
5 upvotes per una domanda di 7 parole che non mostra alcuno sforzo di ricerca? _ [Come faccio a fare una buona domanda?] (Http://stackoverflow.com/help/how-to-ask) _. Sono geloso;) – MickyD