testing

Philisophical Questions about Test-Driven Development

早过忘川 提交于 2020-01-11 17:10:46
问题 I have been perpetually intrigued by test-driven development, but I can never follow through with it when I try it on real projects. I have a couple of philosophical questions that continually arise when I try it: How do you handle large changes? When it comes to testing single functions (some parameters, a result value, few side effects), TDD is a no-brainer. But what about when you need to thoroughly overhaul something large, e.g. switching from a SAX parsing library to a DOM parsing

How can a private class method be tested in Scala?

吃可爱长大的小学妹 提交于 2020-01-11 17:10:07
问题 I have a companion object with a private method, like so: package com.example.people class Person(val age: Int) object Person { private def transform(p: Person): Person = new Person(p.age + 1) } I would like to test this method, with something like: class PersonSpec extends FlatSpec { "A Person" should "transform correctly" in { val p1 = new Person(1) val p2 = Person.transform(p1) // doesn't compile, because transform is private! assert( p2 === new Person(2) ) } } Any help on having test code

How can I make my Selenium tests less brittle?

假装没事ソ 提交于 2020-01-11 15:51:05
问题 We use Selenium to test the UI layer of our ASP.NET application. Many of the test cases test longer flows that span several pages. I've found that the tests are very brittle, broken not just by code changes that actually change the pages but also by innocuous refactorings such as renaming a control (since I need to pass the control's clientID to Selenium's Click method, etc) or replacing a gridview with a repeater. As a result I find myself "wasting" time updating string values in my test

Verify a method call using Moq

心不动则不痛 提交于 2020-01-11 15:05:25
问题 I am fairly new to unit testing in C# and learning to use Moq. Below is the class that I am trying to test. class MyClass { SomeClass someClass; public MyClass(SomeClass someClass) { this.someClass = someClass; } public void MyMethod(string method) { method = "test" someClass.DoSomething(method); } } class Someclass { public DoSomething(string method) { // do something... } } Below is my TestClass: class MyClassTest { [TestMethod()] public void MyMethodTest() { string action="test"; Mock

Difference between Android Instrumentation test and Unit test in Android Studio?

放肆的年华 提交于 2020-01-11 14:47:50
问题 As of Android Studio 1.1rc there's Unit testing support and I'm wondering what's the difference between Android Instrumentation Tests and Unit tests. As I understand it: Unit tests are useful for testing code which doesn't call the Android API, and the Android instrumentation tests are rather integration tests to test Android API specific elements or GUI components. However if you use a framework like Robolectric or Mockito in your unit tests, you can test Android code (without the need of a

How do I write tests correctly using unittest?

独自空忆成欢 提交于 2020-01-11 14:04:53
问题 I am trying to figure out how to write unit tests for functions that I have written in Python - here's the code written below: def num_buses(n): import math """ (int) -> int Precondition: n >= 0 Return the minimum number of buses required to transport n people. Each bus can hold 50 people. >>> num_buses(75) 2 """ bus = int() if(n>=0): bus = int(math.ceil(n/50.0)) return bus I am attempting to write test code but they are giving me fail results - here's code I started with: import a1 import

Clustering: Cluster validation

江枫思渺然 提交于 2020-01-11 12:57:11
问题 I want to use some clustering method for large social network dataset. The problem is how to evaluate the clustering method. yes, I can use some external ,internal and relative cluster validation methods. I used Normalized mutual information(NMI) as external validation method for cluster validation based on synthetic data. I produced some synthetic dataset by producing 5 clusters with equal number of nodes and some strongly connected links inside each cluster and weak links between clusters

unit test via output sanity checks

早过忘川 提交于 2020-01-11 12:16:33
问题 I have often seen tests where canned inputs are fed into a program, one checks the outputs generated against canned (expected) outputs usually via diff. If the diff is accepted, the code is deemed to pass the test. Questions : 1) Is this an acceptable unit test? 2) Usually the unit test inputs are read in from the file system and are big xml files (maybe they represent a very large system). Are unit tests supposed to touch the file system? Or would a unit test create a small input on the fly

How to add client certificate in ASP.NET Web API in-memory testing?

假装没事ソ 提交于 2020-01-11 10:41:52
问题 I want to test my Web API service using in-memory HttpServer . The current setup looks the following: var httpConfig = CreateTestHttpConfiguration(); var server = new HttpServer(httpConfig); var handler = new WebRequestHandler(); var cert = new X509Certificate2("filename", "password"); handler.ClientCertificates.Add(cert); var client = HttpClientFactory.Create(handler, server); I can make requests to the server using these client and everything works except that certificate is not added to

Instantiate multiple spring boot apps in test

我的梦境 提交于 2020-01-11 09:45:11
问题 I have several instances of my spring boot app, which in parallel do some work with DB. Each instance is running in separate JVM. Is it a way to write a test in Java for testing that on one JVM? Like following: Setup some embedded DB for testing purposes or even just mock it. Start 2-5 instances of my Spring boot app Wait some time Stop all started instances Verify DB and check that all the conditions are met. Each instance has its own context and classpath. I think that I could achieve that