title,body,link,tags,view_count,is_answered,score,answer_count,critical points
Tests name convention best practices,"<p>Does anyone knows some good references to guide me in order to give automated tests, the best possible names? I know the rules but want good references to support some of the names that I used. Thanks in advance</p>
",https://stackoverflow.com/questions/74113578/tests-name-convention-best-practices,"['testing', 'conventions', 'names']",32,FALSE,0,0,how to name tests?
Best practices for testing multi module android app,"<p>I have an application with 4 different modules. Network layer is separated in different module and I created a fake repository for unit testing in it.
The problem is that I cannot access that fake repository in my main module test classes (for creating test classes for viewmodels). I tried different solutions from google and none of them are working.</p>
<p>If I use something like this in gradle</p>
<pre><code>testImplementation(project(&quot;:data&quot;))
</code></pre>
<p>Test classes are still not visible.</p>
<p>My question is what are the best practices when writing tests for multi module android application? Is good practice to create one module for test and put everything related to testing from every module in that one? Or is there a way to make test classes from other modules visible in my main module?</p>
",https://stackoverflow.com/questions/73908839/best-practices-for-testing-multi-module-android-app,"['android', 'gradle', 'testing']",161,FALSE,0,0,My question is what are the best practices when writing tests for multi module android application?
What are the best practices to deal with external resources in E2E tests?,"<p>in my team we use E2E tests, and we have the following dilemma about dealing external resources:</p>
<ol>
<li>We want our E2E tests to test whole flows - including dealing with the DB, upload images to our S3 servers and etc.</li>
<li>It occured that one of the external resources had some problems for a while - for example one of the S3 servers had a problem that avoided our tests to upload images to it, so our tests failed but the internal code was just fine. Our tests also run in the CI so when this external resource was down we couldn't do any merges and etc because the tests failed.</li>
</ol>
<p>We want our tests to block merges in cases that we have an actual bugs that we didn't see in manual tests.</p>
<p>I would like to know what is the best practice to deal with external resources in E2E tests - should we mock them so our tests won't depend on external problems or should we still use the external resources in the tests?</p>
<p>Thanks ahead.</p>
",https://stackoverflow.com/questions/72739902/what-are-the-best-practices-to-deal-with-external-resources-in-e2e-tests,"['testing', 'mocking', 'continuous-integration', 'e2e-testing', 'e2e']",123,FALSE,1,0,What is the best practice to deal with external resources in E2E testing?
Best practices for iOS back-end versioning,"<p>I've never worked at a tech company. I built an app from scratch with a NodeJS API and MongoDB hosted on AWS.</p>
<p>I will start hiring back-end developers to work with me.</p>
<p>What is the best way to making changes to the backend? All the .js files are stored in a repository, but what's the best way to test changes to the API before shipping?</p>
<p>The app is live on the app store. Should I put a duplicate build on TestFlight and connect it to version_2.js files and test it like that?</p>
<p>Or is there a better way to do it? Curious about what industry folks typically do.</p>
",https://stackoverflow.com/questions/72164691/best-practices-for-ios-back-end-versioning,"['ios', 'testing', 'versioning', 'testflight']",195,TRUE,-1,1,"Best way to make/test changes in the backend?
* Environments
* Unit, Integration, UI testing
* Source control
* Project management
* Semantic versioning"
What are the best practices in automating end 2 end testcases?,"<p>I am trying to get a clear understanding of what e2e test cases look like.
And I am confused about how e2e testing is handled by companies. In my understanding, e2e testing is the testing of different systems and layers of the application. An example: if I am trying to e2e test a &quot;purchase&quot; endpoint I would have to also check the DB layer and do a purchase flow using UI. Please correct me if I am wrong.
SO the questing is - How would I automate this type of scenario? Do I test UI, API, and DB separately or do I write a huge test case? Also if my automation framework only handles API and DB layers. I am even able to create an e2e test case if I don't test the Web Layer?</p>
",https://stackoverflow.com/questions/71200615/what-are-the-best-practices-in-automating-end-2-end-testcases,"['java', 'testing', 'automation', 'frameworks', 'e2e']",117,FALSE,0,0,How to automate e2e scenario tests? Automate flow? Automate and test different layers separately?
Test utils files in Angular. What are the Best practices?,"<p>In Angular I want to share some utils for using across my tests.</p>

<p>What would be the best practice/standard to do so?</p>

<p>I.e. To test a component/service/whatever you create a file with the same name and the extension <code>.spec.ts</code> and placed in the same folder. For a test utils what will be the best placement and naming? Also ending in <code>.spec.ts</code>?</p>
",https://stackoverflow.com/questions/58852483/test-utils-files-in-angular-what-are-the-best-practices,"['angular', 'testing', 'karma-jasmine']",1482,TRUE,1,2,How to share test files across various tests?
What are the best practices for testing bulk email sends?,"<p>What are the best practices (or even just <em>any</em> way at all) of testing bulk email sends?</p>
<p>I'm using the Twilio <a href=""https://github.com/sendgrid/sendgrid-csharp"" rel=""nofollow noreferrer"">SendGrid C# library</a> with the built-in <a href=""https://github.com/sendgrid/sendgrid-csharp/blob/main/src/SendGrid/Helpers/Mail/MailHelper.cs#L173"" rel=""nofollow noreferrer"">CreateMultipleEmailsToMultipleRecipients</a> function. Here's <a href=""https://github.com/sendgrid/sendgrid-csharp/blob/main/USE_CASES.md#send-multiple-emails-to-multiple-recipients"" rel=""nofollow noreferrer"">an example</a> of that function in the context of some code.</p>
<p>SendGrid does not appear to allow me to just send myself (i.e. a single email address) a ton of emails, it ends up only delivering only a few.</p>
<p>The end goal is that I want to see that my code is using the CreateMultipleEmailsToMultipleRecipients function correctly, and that it works for 100 users, then 1000 users (which is the supposed limit of that function IIRC).</p>
",https://stackoverflow.com/questions/69228552/what-are-the-best-practices-for-testing-bulk-email-sends,"['email', 'testing', 'sendgrid', 'sendgrid-api-v3']",251,FALSE,0,0,No answers/suggestions were made for this question
Unit tests on setter &amp; getter - best practices,"<p>I got 2 functions I want to test in my class - <code>get</code> &amp; <code>set</code>. Those 2 functions do actual logic and not just return and set, so I would like to test them.</p>
<p>I have started to write unit tests for those functions, in pseudo code something like this:</p>
<pre><code>value_to_write = 5
my_class.set_value(value_to_write)
read_value = my_class.get_value()
assert(read_value == value_to_write)
</code></pre>
<p>So in this example we <code>set</code> and then check with <code>get</code> that the <code>set</code> was successful.<br />
But then I remembered the best practice that says &quot;Test should check one and only thing&quot;. In this example I check <code>set</code> and <code>get</code> together.</p>
<p>What is the best practice for this example?<br />
Is creating 3 functions of checking the <code>set</code>, checking the <code>get</code> and finally checking that the value written with the <code>set</code> is correct (like the example above)?<br />
The problem with this method is that the third test already covers the first and second one, so I wonder what is the point</p>
",https://stackoverflow.com/questions/69371284/unit-tests-on-setter-getter-best-practices,"['unit-testing', 'testing']",233,FALSE,0,2,"* Naming convention for functions and variables should be indicative of its purpose
* Other suggests are question specific - can't be generalized"
Best practices on reusing test inputs in JavaScript,"<p>I've written a fixed-point math library, which comes in two flavors: the signed and the unsigned flavor.</p>
<p>The tests across the two flavors have lots of inputs in common. E.g. for the <code>avg</code> function:</p>
<pre><code>// Signed tests inputs
context(&quot;when one operand is zero and the other is not zero&quot;, function () {
  const testSets = [
    [fp(&quot;-4&quot;), fp(&quot;0&quot;)],
    [fp(&quot;0&quot;), fp(&quot;-4&quot;)],
    [fp(&quot;0&quot;), fp(&quot;4&quot;)],
    [fp(&quot;4&quot;), fp(&quot;0&quot;)],
  ];
  // ...
});


// Unsigned tests inputs
context(&quot;when one operand is zero and the other is not zero&quot;, function () {
  const testSets = [
    [fp(&quot;0&quot;), fp(&quot;4&quot;)],
    [fp(&quot;4&quot;), fp(&quot;0&quot;)],
  ];
  // ...
});
</code></pre>
<p>The values in the <code>testSets</code> arrays are duplicated. Links to GitHub:</p>
<ul>
<li><a href=""https://github.com/hifi-finance/prb-math/blob/5f140e5ec3b8c88ead638ea4362a54c80abca74e/test/prbMathSd59x18/pure/avg.ts"" rel=""nofollow noreferrer"">Signed tests</a></li>
<li><a href=""https://github.com/hifi-finance/prb-math/blob/5f140e5ec3b8c88ead638ea4362a54c80abca74e/test/prbMathUd60x18/pure/avg.ts"" rel=""nofollow noreferrer"">Unsigned tests</a></li>
</ul>
<p>The question is, how to refactor my code base such that I don't repeat myself? Is there a &quot;best practice&quot; for this scenario? I read about <a href=""https://jestjs.io/docs/snapshot-testing"" rel=""nofollow noreferrer"">snapshot testing</a>, though that doesn't tackle test inputs. I said that maybe I should <a href=""https://github.com/Marak/Faker.js"" rel=""nofollow noreferrer"">fake</a> the data. But I'm not sure that makes sense in my case, because the inputs for my mathematical functions are bound by a domain.</p>
<p>Note: I am running my tests with <a href=""https://mochajs.org/"" rel=""nofollow noreferrer"">Mocha</a>.</p>
",https://stackoverflow.com/questions/69303215/best-practices-on-reusing-test-inputs-in-javascript,"['javascript', 'testing', 'design-patterns', 'mocha.js']",37,FALSE,0,0,"* Snapshot testing is discussed
* How to refactor code to avoid duplication"
Best practices to have a test base class - .NET,"<p>I'm starting to write tests for an app, something like:</p>
<pre><code>namespace API.Test
{
    public class HealthCheckTests : IClassFixture&lt;WebApplicationFactory&lt;Startup&gt;&gt;
    {
        private readonly HttpClient _httpClient;

        public HealthCheckTests(WebApplicationFactory&lt;Startup&gt; factory)
        {
            _httpClient = factory.CreateDefaultClient(new Uri(&quot;http://localhost/healthcheck&quot;));
        }

        [Fact]
        public async Task HealthCheck_ReturnsOk()
        {
            var response = await _httpClient.GetAsync(&quot;&quot;);

            response.EnsureSuccessStatusCode();
        }
    }
}
</code></pre>
<p>Of course, I got more controllers so I want to &quot;reuse&quot; the client for example. What do you think it's a better approach.</p>
<ul>
<li>Abstract class initializing constructor</li>
<li>Class and instantiate in constructor like composition.</li>
<li>Other</li>
</ul>
",https://stackoverflow.com/questions/69130999/best-practices-to-have-a-test-base-class-net,"['.net', 'testing', 'xunit']",173,FALSE,0,1,No suggestions were provided
what is the best practices for sandbox database,"<p>We are currently working for a booking website and there are many partners that can integrate with our website via REST APIs. We need to give our partner a test environment during the integration process and we have three suggestions</p>
<ol>
<li><p>Create the testing booking and production booking on the same database and the same table with different number formats. ( like add T letter before the booking number)</p>
</li>
<li><p>Create a different table for the testing booking.</p>
</li>
<li><p>Both testing and production bookings in the same table and the same format but with a flag to distinguish the testing booking.
Please advise us with the most correct solution or if there is another solution.</p>
</li>
</ol>
",https://stackoverflow.com/questions/67008573/what-is-the-best-practices-for-sandbox-database,"['mysql', 'laravel', 'testing', 'environment', 'sandbox']",154,FALSE,0,0,"Question is quite specific, no suggestions were provided"
Best practices for using typescript with node,"<p>For react rthere is create-react-app which codifies best practices in project setup.</p>
<p>Something is missing in node. If I want to develop and deploy a typescript application on node.js I need at least 3 &quot;targets&quot;:</p>
<ul>
<li><strong>start</strong> runs a development build of the app</li>
<li><strong>test</strong> executes unittests (e.g. jest)</li>
<li><strong>build</strong> compiles the typescript to something node can understand - for deployment.</li>
</ul>
<p>For all this functionality there are tools like <a href=""https://github.com/kulshekhar/ts-jest"" rel=""nofollow noreferrer"">ts-jest</a> <a href=""https://github.com/TypeStrong/ts-node"" rel=""nofollow noreferrer"">ts-node</a> and <a href=""https://www.typescriptlang.org/docs/handbook/compiler-options.html"" rel=""nofollow noreferrer"">tsc</a>.</p>
<p>This all somewhat works but i get all kinds of hickups. Currently the <code>scripts</code> section in <code>package.json</code> looks like this:</p>
<pre><code>  &quot;scripts&quot;: {
    &quot;build&quot;: &quot;tsc -p src&quot;,
    &quot;start&quot;: &quot;yarn run nodemon -e js,json,graphqls,ts,yaml --signal SIGHUP -x ts-node src/index.js&quot;,
    &quot;test&quot;: &quot;rm -Rf dist/ ; yarn run ts-jest --testPathIgnorePatterns=tests/&quot;,
  },
</code></pre>
<p>But this has all kinds of issues. <code>tsc</code> uses <code>src/tsconfig.json</code>. The other two use <code>./tsconfig.json</code>. without that the output will be in <code>./dist/src/</code> and the difference in dir depth will mess up relative file access to non-source files.</p>
<p><code>ts-node</code> and <code>tsc</code> seem to report different errors. For example <code>tsc</code> seems to be fine with accidentaly coexisting js and ts files while ts-node crashes with an opaque <code>emit error</code>. The contents of <code>./dist</code> confuse the other tools - thy load and execute files from <code>./dist</code> instead from <code>./src</code>.</p>
<p>So how do I set up a reloading development server (<code>yarn start</code>), a test runner (<code>yarn test</code>) and a production compillation (<code>yarn build</code>) all using the same configuration files, resting at the same directory depth and behaving all the same?</p>
",https://stackoverflow.com/questions/64986664/best-practices-for-using-typescript-with-node,"['node.js', 'typescript', 'testing', 'build', 'jestjs']",438,TRUE,-1,1,Contents of the post are irrelevant to this research
Best practices for Docker compose testing?,"<p>In <a href=""https://github.com/unee-t/bugzilla-customisation/blob/master/docker-compose.yml"" rel=""nofollow noreferrer"">complex orchestrations of docker-compose.yaml stacks</a>, I'm keen to do a simple integration test that shows the system works. I'm not entirely sure though this might be called an ""end to end"" test.</p>

<p>I've seen <a href=""https://github.com/bats-core/bats-core"" rel=""nofollow noreferrer"">https://github.com/bats-core/bats-core</a> used in helm charts, though not so much in <a href=""https://github.com/search?q=bats+filename%3Adocker-compose.yml"" rel=""nofollow noreferrer"">docker-compose.yml</a>.</p>

<p>Is there some other testing method that I am missing? Or is using bats in a docker-compose context, a reasonable approach? My end goal is that the application can be testing in some CI service like TravisCI/CircleCI using a simple <code>docker-compose.yml</code> &amp; a command not too dissimilar to <code>docker-compose up</code></p>
",https://stackoverflow.com/questions/59024442/best-practices-for-docker-compose-testing,"['docker', 'testing', 'docker-compose']",114,FALSE,1,0,No suggestions were provided
Best way to distribute Flutter application Android &amp; iOS. Best Practices in Flutter Beta Distribution,"<p>How can I distribute my Flutter app (both Android &amp; iOS) Beta build. I was going through with Crashlytics Beta Distribution. But I think there is some problem distributing Android &amp; iOS app with same name or ids.</p>
",https://stackoverflow.com/questions/57703631/best-way-to-distribute-flutter-application-android-ios-best-practices-in-flut,"['testing', 'flutter', 'distribution', 'beta-testing']",3390,TRUE,9,1,The answer doesn't discuss any general practices. It gives some suggestions of how to make the code base compatible for android and ios
What are best practices for unit testing multiple functions that have very similar test scenarios?,"<p>Let's say I have two pure functions, <code>pureFn1</code> and <code>pureFn2</code>. These functions must pass similar tests.</p>

<pre><code>describe(""generic function"", () =&gt; {
  it(""should fulfill condition 1"", testCondition1);

  it(""should fulfill condition 2"", testCondition2);

  it(""should fulfill condition 3"", testCondition3);

  it(""should fulfill condition 4"", testCondition4);
});
</code></pre>

<p>How would the similar tests be written for these functions? Should the test suite be reusable?</p>

<p>For example, if we reused the test suite, it will end up looking like this:</p>

<pre><code>const reusableTestSuite = (codeUnderTest) =&gt; {
  describe(`${codeUnderTest.name}`, () =&gt; {
    it(""should fulfill condition 1"", testCondition1(codeUnderTest));

    it(""should fulfill condition 2"", testCondition2(codeUnderTest));

    it(""should fulfill condition 3"", testCondition3(codeUnderTest));

    it(""should fulfill condition 4"", testCondition4(codeUnderTest));
  });
};

reusableTestSuite(pureFn1);
reusableTestSuite(pureFn2);
</code></pre>

<p>This is pretty DRY, but the problem is there is an abstraction which might make the tests harder to read and modify, and thus possibly discourage devs from writing more tests in the name of speed and ease. This is discussed in point 8 of <a href=""https://medium.com/@me_37286/yoni-goldberg-javascript-nodejs-testing-best-practices-2b98924c9347"" rel=""nofollow noreferrer"">this article</a>. When these abstracted tests break, the next developer might hate to read it.</p>

<p>The other option is to copy-paste the tests:</p>

<pre><code>describe(""pureFn1"", () =&gt; {
  it(""should fulfill condition 1"", testCondition1Fn1);

  it(""should fulfill condition 2"", testCondition2Fn1);

  it(""should fulfill condition 3"", testCondition3Fn1);

  it(""should fulfill condition 4"", testCondition4Fn1);
});

describe(""pureFn2"", () =&gt; {
  it(""should fulfill condition 1"", testCondition1Fn2);

  it(""should fulfill condition 2"", testCondition2Fn2);

  it(""should fulfill condition 3"", testCondition3Fn2);

  it(""should fulfill condition 4"", testCondition4Fn2);
});
</code></pre>

<p>This is full-on code duplication. There is no abstraction. If we had two functions with 20 common properties between them, we would have to copy and paste 20 tests and remember to update all the similar tests when one changes, forever.</p>

<p>So between these approaches, which is the better method? Or is there a third method, a best practice in writing unit tests in a way that we get the benefits of abstraction while not making it hard for the next developer to immediately learn what went wrong, and thus <em>not</em> discourage them from writing more of these tests?</p>
",https://stackoverflow.com/questions/56664159/what-are-best-practices-for-unit-testing-multiple-functions-that-have-very-simil,"['javascript', 'node.js', 'unit-testing', 'testing', 'mocha.js']",189,FALSE,1,0,The question deals with abstraction of common elements from multiple test cases but no advice is provided
Best practices for unit testing in Python - multiple functions apply to same object,"<p>I have a bunch of functions which apply to a similar object, for example a Numpy array which represents an n-dimensional box:</p>

<pre class=""lang-py prettyprint-override""><code># 3-D box parameterized as:
#     box[0] = 3-D min coordinate
#     box[1] = 3-D max coordinate
box = np.array([
    [1, 3, 0],
    [4, 5, 7]
])
</code></pre>

<p>Now I have a whole bunch of functions that I want to run on lists of boxes, eg. <code>volumes</code>, <code>intersection</code>, <code>smallest_containing_box</code>, etc. In my mind here is the way I was hoping to set this up:</p>

<pre class=""lang-py prettyprint-override""><code># list of test functions:
test_funcs = [volume, intersection, smallest_containing_box, ...]
# manually create a bunch of inputs and outputs
test_set_1 = (
    input = [boxA, boxB, ...], # where each of these are np.Array objects
    output = [
        [volA, volB, ...], # floats I calculated manually
        intersection, # np.Array representing the correct intersection
        smallest_containing_box, # etc.
    ]
)
# Create a bunch of these, eg. test_set_2, test_set_3, etc. and bundle them in a list:
test_sets = [test_set_1, ...]
# Now run the set of tests over each of these:
test_results = [[assertEqual(test(t.input), t.output) for test in test_funcs] for t in test_sets]
</code></pre>

<p>The reason I want to structure it this way is so that I can create multiple sets of (input, answer) pairs and just run all the tests over each. Unless I'm missing something, the structure of <code>unittest</code> doesn't seem to work well with this approach. Instead, it seems like it wants me to create an individual TestCase object for each pair of function and input, i.e.</p>

<pre class=""lang-py prettyprint-override""><code>class TestCase1(unittest.TestCase):
    def setUp(self):
        self.input = [...]
        self.volume = [volA, volB, ...]
        self.intersection = ...
        # etc.

    def test_volume(self):
        self.assertEqual(volume(self.input), self.volume)

    def test_intersection(self):
        self.assertEqual(intersection(self.input), self.output)

    # etc.

# Repeat this for every test case!?
</code></pre>

<p>This seems like a crazy amount of boilerplate. Am I missing something?</p>
",https://stackoverflow.com/questions/55208694/best-practices-for-unit-testing-in-python-multiple-functions-apply-to-same-obj,"['python', 'unit-testing', 'testing']",1993,FALSE,1,2,"Setup of tests before running all tests, no suggestions provided"
Testing Best Practices possibly with regard to Gherkin but probably not,"<p>A coworker and I are having an argument about the proper way to test. I'll lay them out as neutrally as I can, and won't give my opinion in this post.</p>

<p>This is written in gherkin. Substitute whatever pseudocode you want to.</p>

<pre><code>Given I am a registered user
When I submit my credentials
Then I can login
</code></pre>

<p><em>Case one:</em></p>

<pre><code>Given I am a registered user 
    (instantiates the user,
    stores the user to scenario-global memory,
    adds the user to the db with an API endpoint
    stores the API endpoint result to scenario-global memory [200, ""Success message""])

When I submit my credentials
    (test the result of the previous step [200],
    fills the credential field(s),
    clicks submit, stores the result to scenario-global memory [200, ""Success message""])

Then I can login
    (tests the results of the previous step)
</code></pre>

<p><em>Case two:</em></p>

<pre><code>Given I am a registered user
    (instantiates the user,
    stores the user in scenario-global memory,
    adds the user to the db, tests the result of the db command)

When I submit my credentials
    (fills the UI credential field(s),
    clicks submit)

Then I can login
    (perform some operation that only a logged-in user could do [see the my profile button/call some api endpoint])
</code></pre>

<p>&#x200B;</p>

<p>The contention is whether or not the Then step can rely on the result from a previous operation.</p>
",https://stackoverflow.com/questions/53842526/testing-best-practices-possibly-with-regard-to-gherkin-but-probably-not,"['testing', 'automated-tests', 'cucumber', 'gherkin']",30,FALSE,0,2,No suggestions were provided
Spark Testing: is it worth? (Best Practices),"<p>Using Apache Spark, I was wondering if it is really valuable producing test and in case at which level.</p>

<p>Reading <a href=""http://shop.oreilly.com/product/0636920034957.do"" rel=""nofollow noreferrer"">Spark: The Definitive Guide</a> they suggest:</p>

<blockquote>
  <p>The business logic in your pipelines will likely change as well as the input data. Even more importantly, you want to be sure that what you’re deducing from the raw data is what you actually think that you’re deducing. This means that you’ll need to do robust logical testing with realistic data to ensure that you’re actually getting what you want out of it. </p>
</blockquote>

<p>Which suggests to introduce some sort of testing.</p>

<p>But what impress me is:</p>

<blockquote>
  <p>One thing to be wary of here is trying to write a bunch of “Spark Unit Tests” that just test Spark’s functionality. You don’t want to be doing that; instead, you want to be testing your business logic and ensuring that the complex business pipeline that you set up is actually doing what you think it should be doing.</p>
</blockquote>

<p>Which outlines that Unit Testing is discouraged by the authors of this book (correct me if I misinterpreted).</p>

<p>What probably it is worth to test instead is the logic of the Data Transformation applied through Spark.</p>

<p>Again from the book:</p>

<blockquote>
  <p>First, you might maintain a scratch space, such as an interactive notebook or some equivalent thereof, and then as you build key components and algorithms, you move them to a more permanent location like a library or package. The notebook experience is one that we often recommend (and are using to write this book) because of its simplicity in experimentation</p>
</blockquote>

<p>Which suggests to test your Data Transformation logic in an interactive environment such as Notebooks (e.g. Jupyter Notebooks for Pyspark). Basically you directly see what the transformations produce.</p>

<p>So I am asking to people with more experience than me, do you agree with the cited points from the book? (or am I misinterpreting) <strong>Can they be used as a sort of Best Practices in this domain?</strong> (for example avoiding Unit Tests, promoting instead higher level testing like Logic / Integration Tests)</p>
",https://stackoverflow.com/questions/52083205/spark-testing-is-it-worth-best-practices,"['apache-spark', 'testing', 'automated-tests', 'analytics']",289,TRUE,-1,1,No suggestions were provided
What are the best practices for appium framework using page opject model,"<p>I am developing an automation framework for a mobile application using Appium (in java). I started with creating a class per view, in each class, I find and initialize elements of that class. Now after a while I understand my configuration for the framework is not correct and I'm not able to expand it. It would be great if anyone can introduce me an implemented framework on Github.</p>

<p>here is my config class, I use setdriver() to set a driver wherever I need.</p>

<pre><code>public class Config {

public AndroidDriver&lt;AndroidElement&gt; driver;

public static AndroidDriver&lt;AndroidElement&gt; SetDriver() throws MalformedURLException {

    File appPath= new File(""src"");
    File app = new File(appPath,""My-debug.apk"");

    DesiredCapabilities cap = new DesiredCapabilities();
    cap.setCapability(MobileCapabilityType.DEVICE_NAME, ""myDevice"");
    cap.setCapability(MobileCapabilityType.APP,app.getAbsolutePath());
    cap.setCapability(""autoGrantPermissions"",true);
    cap.setCapability(""appWaitActivity"",""com.xxxx.xxxx.ui.launch.LaunchActivity"");
    AndroidDriver&lt;AndroidElement&gt; driver = new AndroidDriver&lt;AndroidElement&gt;(new URL(""http://127.0.0.1:4723/wd/hub""),cap);

    return driver;
}
</code></pre>

<p>Thank you in advance.</p>
",https://stackoverflow.com/questions/53290266/what-are-the-best-practices-for-appium-framework-using-page-opject-model,"['selenium', 'testing', 'automation', 'appium']",1640,TRUE,2,2,"Code specific suggestions were provided, can't be generalized"
Best practices for testing a web app based on http calls,"<p>I've built a web app that aggregates trading and blockchain data from several API's and displays them in a React frontend(node backend)</p>

<p>What is the best way to implement tests to check for data integrity or when there are issues?</p>

<p>I am extremely new to testing and would appreciate any guidance/direction. Have gone through several testing frameworks and libraries, and am kind of dumbfounded.</p>
",https://stackoverflow.com/questions/52124255/best-practices-for-testing-a-web-app-based-on-http-calls,"['node.js', 'reactjs', 'testing', 'mocha.js', 'chai']",65,TRUE,1,1,"* Apps are not tested for ""data integrity"" 
* Jest, Jasmine, Mocha are suggested for unit testing
* e2e - TestCafe
* API testing - Mocha, Chai, Supertest or Chakram"
What are the best practices for Testing in Angular?,"<p>I have an <code>AppComponent</code> and in its html template, I have <code>BannerComponent</code> and <code>WelcomeComponent</code> (indicated by <code>&lt;app-banner&gt;</code> and <code>&lt;app-welcome&gt;</code>).
So in the test case, if I declare the real components, I'll also have to declare their nested components and provide for all services injected in any component in the tree.
What is the recommended practice? Can I just use <code>imports: [ AppModule ]</code> or do I declare all the components and their nested components and all the services injected into them??</p>

<p>If I just import AppModule, will it take the real <code>RouterModule</code> (if used by the <code>AppModule</code>) or can I just override it by using <code>RouterTestingModule</code>??</p>

<p>If I declare all the component, will give me a better idea that the component under test integrates well with all the other dependent components. Is it a good practice? Also, is it a good practice to use <code>APP_ERRORS_SCHEMA</code>?</p>
",https://stackoverflow.com/questions/52751655/what-are-the-best-practices-for-testing-in-angular,"['angular', 'testing', 'angular-test']",328,FALSE,1,1,Angular specific suggestions
Simultaneous integration test using the same SQL database best practices,"<p>My .NET Framework application talks to a SQL DB using Entity Framework. I'm trying to develop an integration test for the application. Right now the way I do it is to clean up the SQL DB during the test setup phrase, i.e every time I run the test, the test will start off with a clean db. </p>

<p>However, if 2 people run the same time roughly at the same time, I might run into trouble since both people are reading and writing <strong>the same DB at the same time.</strong></p>

<p>I did some research, looks like the best way is to provision a new DB in the setup and delete the db during teardown. </p>

<p>I wonder if there is a simpler approach? Thanks.</p>
",https://stackoverflow.com/questions/50863330/simultaneous-integration-test-using-the-same-sql-database-best-practices,"['sql', '.net', 'entity-framework', 'testing', 'integration-testing']",79,FALSE,0,0,How to avoid & test simulatenous db changes?
Auth0 test account best practices,"<p>I am working on a project using Auth0 for authentication, and I am starting to write client side tests for this project.  I would like to create a test account for this project that can allow a script to regularly and automatically run through different scenarios in the application.</p>

<p>The problem is that I'd like to run these tests on a stack with actual customer data.  This means the credentials/password for this account need to be hidden from the public.  I should be able to rotate these credentials easily as well so nobody I work with has permanent access to the customer data.  I'd also like to keep any credentials out of my checked in codebase, in case that leaks to the public.</p>

<p>What are some best practices for this situation?  Are there similar problems that have solutions I can use for inspiration?</p>
",https://stackoverflow.com/questions/49246823/auth0-test-account-best-practices,"['security', 'authentication', 'testing', 'automated-tests', 'auth0']",220,FALSE,1,1,Use of CI server (Jenkins) 
Unit testing a complex renderer class (Best Practices),"<p>I'm trying to test a class which purpose is taking a specification of what to do with a BufferedImage array and proccess it.</p>

<p>I'm concerned about how to aproach this task, it makes no sense to me just duplicate the function code on the test in order to generate a ""expected bufferedImage array"" and check if the generated BufferedImages are equals to the returned by the class methods.</p>

<p>I've read some slightly similar questions here, but the answers was ""charge expected images from file and check with returned ones by class methods"" but that sounds real hard to maintain if the proccess changes, new methods are added to the renderer class, it's hard or imposible pregenerate a resulting image or simply the class is refactorized and functions are splitted.</p>

<p>My actual question might be: Is there a little more elegant, ""better to maintain"" way to do that. I haven't so much experience with unit testing so i'm not sure about how to do this.</p>

<p><strong>EDIT:</strong> sorry for the long code, i simplified and translated it. Excuse me if i did a bad translation. english it's not my main language.</p>

<pre><code>public class Renderer extends SwingWorker&lt;BufferedImage[], Integer&gt;
{
  private Device device;
  private Main main;
  private Controller controller;
  public static final int FPS = 25;



  public Renderer(Device device, Main main, Controller controller)
  {
    this.device = device;
    this.main = main;
    this.controller = controller;
  }

  @Override
  protected BufferedImage[] doInBackground() throws Exception
  {

    // rendering image array
    BufferedImage[] output = renderize(main.getActualEscene());
    LOG.log.log(Level.INFO, ""Rendering"");
    // getting how many times should repeat 
    String stringRepeat =
        main.getActualEscene().getProperties().get(TextProperties.REPEAT.toString());
    int repeat = (stringRepeat == null) ? 1 : Integer.parseInt(stringRepeat);
    // getting text speed
    String stringFps =
        main.getActualEscene().getProperties().get(TextProperties.TEXT_SPEED.toString());
    int fps = (stringFps == null) ? FPS : Integer.parseInt(stringFps);
    if (!this.isCancelled()) // if this task is not cancelled
    {
      // we create a pre-viewer
      controller.setPreviewer(
          new Previewer(controller, repeat, fps, main.getActualEscene()));
      SwingUtilities.invokeLater(new Runnable()
      {// sincronizing this code with AWT thread

        @Override
        public void run()
        { // if it's not cancelled
          if (controller.getPreviewer() != null
              &amp;&amp; !controller.getPreviewer().isCancelled())
          {
            controller.getPreviewer().execute(); //execute the task
          }

        }

      });
    }


    return output;
  }

  /**
   * Renders a scene and transforms it in a image array, then save it to the scene
   * 
   * @param scene -&gt; scene 
   * @return an array with the scene frames
   */
  public BufferedImage[] renderize(Scene scene)
  {
    BufferedImage[] output = null; // end result
    BufferedImage[] base = new BufferedImage[1]; // base image
    BufferedImage[] animationImages = null; // animation layer
    BufferedImage[] textLayer = null; // text layer
    BufferedImage[] overLayer = null; // overlayer


    // omitted long process to retrieve image properties

    // once the text properties are retrieved if it's not null it will be rendered
    if (text != null)
    {
      String backgroundColorString =
          scene.getProperties().get(TextProperties.BACKGROUND_COLOR.toString());
      int backGroundcolorInt = Integer.parseInt(backgroundColorString);
      if (animationImages != null) // if there is an animation layer we create a same size text layer
      {
        textLayer = new BufferedImage[animationImages.length];
      } else 
      {
        textLayer = new BufferedImage[1];
      }
      for (int i = 0; i &lt; textLayer.length; i++)
      {
        textLayer[i] = new BufferedImage(device.getWidth(), device.getHeight(),
            BufferedImage.TYPE_INT_ARGB);
      }
      String font = scene.getProperties().get(TextProperties.FONT.toString());
      int lettersHeigth = device.getHeight() / 3;
      int colorNumber =
          Integer.parseInt(scene.getProperties().get(TextProperties.TEXT_COLOR.toString()));
      textLayer = addTextToAImage(text, font, lettersHeigth, new Color(colorNumber),
          new Color(backGroundcolorInt), textLayer);
    }
    // has it overlayer?

    if (scene.getProperties().containsKey(AnimationProperties.OVER.toString())) // if it has over
    {
      String over = scene.getProperties().get(AnimationProperties.OVER.toString());
      overLayer =
          this.readingImagesFromAnimation(OverLibrary.getInstance().getOverByName(over));
    }

    // mixing layers
    output = base; // adding base base
    if (animationImages != null) // if there is animation layer we add it
    {
      output = mixingTwoImages(output, animationImages);
    }
    if (textLayer != null) // if there is text layer
    {
      output = mixingTwoImages(output, textLayer);
    }
    if (overLayer != null) //if there is overlayer
    {
      output = mixingTwoImages(output, overLayer);
    }
    // delimiting image operative zone.
    output = delimite(output, device);
    main.getActualEscene().setPreview(new Preview(output));
    LOG.log.log(Level.INFO, ""Rendering scene finished: "" + scene.getNombre());
    return output;

  }

  /**
   * Apply the device mask to an image. Delimiting the scene operative zone.
   * 
   * @param input -&gt; BufferedImage array which need to be delimited
   * @param device -&gt; device which it mask need to be applied
   * @return An BufferedImage array with a delimited image for the device.
   */
  private BufferedImage[] delimite(BufferedImage[] input, Device device)
  {
    BufferedImage[] output = new BufferedImage[input.length];
    for (int i = 0; i &lt; output.length; i++) // copy all original frames
    {
      output[i] = new BufferedImage(device.getWidth(), device.getHeight(),
          BufferedImage.TYPE_INT_ARGB);
      Graphics2D graphics = output[i].createGraphics();
      graphics.drawImage(input[i], 0, 0, null);
    }

    for (int i = 0; i &lt; output.length; i++) // for each frame
    {
      for (int j = 0; j &lt; output[i].getHeight(); j++) // for each row
      {
        for (int k = 0; k &lt; output[i].getWidth(); k++) // for each column
        {
          if (!device.estaEnZonaOperativa(j, k)) // if the coordinate is not in the operative zone
          {
            int pixel = 0x00000000; // we create a transparent pixel
            output[i].setRGB(j, k, pixel); // set the original pixel with this new one
          }

        }
      }
    }
    return output;
  }

  /**
   * method that reads an animation images and returns it into an array
   * 
   * @param animation -&gt; animación de la que obtendremos sus image
   * @return array de BufferedImage con los frames de la animación ordenados por orden de lectura
   *         ascendente.
   */
  private BufferedImage[] readingImagesFromAnimation(Animation animation)
  {
    BufferedImage[] output = new BufferedImage[animation.getData().length];
    for (int i = 0; i &lt; animation.getData().length; i++) // for each frame
    {
      try
      {
        File ruta = animation.getData()[i]; // getting its path
        output[i] = ImageIO.read(ruta); // reading from the path and save it into output
      } catch (IOException e)
      {
        LOG.log.log(Level.SEVERE, ""error reading animation file: "" + animation.getData()[i],
            e);
      }
    }
    return output;
  }

  /**
   * create a text layer an add it to the image parameter center
   * 
   * @param text -&gt; text to include
   * @param font -&gt; font of the text
   * @param size -&gt; size
   * @param color -&gt; text color
   * @param image -&gt; image you want to add text
   * @return a text layer that need to be mixed with original one.
   */
  private BufferedImage[] addTextToAImage(String text, String font, int size, Color color,
      Color backgroundColor, BufferedImage[] image)
  {
    // we set the size of the output as the same of the original image
    BufferedImage[] output = new BufferedImage[image.length];
    for (int i = 0; i &lt; image.length; i++) // for each frame
    {
      output[i] = new BufferedImage(image[i].getWidth(), image[i].getHeight(),
          BufferedImage.TYPE_INT_ARGB); // we create a single new image
      Graphics2D graphics = output[i].createGraphics(); // get its graphics
      // calculate for metrics
      Font font = new Font(font, Font.PLAIN, size); // create a font
      graphics.setFont(font); // setting it into the graphics
      FontMetrics fontMetrics = graphics.getFontMetrics(font); // generating metric object

      // calculate the text coordinates
      int x = (image[i].getWidth() - fontMetrics.stringWidth(text)) / 2;
      int y = ((image[i].getHeight() - fontMetrics.getAscent() - fontMetrics.getDescent()) / 2)
          + fontMetrics.getAscent();
      int width = fontMetrics.stringWidth(text); // usefull metric to set a brackground
      int height = fontMetrics.getAscent() + fontMetrics.getDescent(); 

      // setting a background
      graphics.setColor(backgroundColor);
      graphics.fill(new Rectangle(x, y - fontMetrics.getAscent(), width, height));

      // drawing text
      graphics.setColor(color); // setting a color for text
      graphics.drawString(text, x, y); 
    }
    return output;
  }

  /**
   * method to join two bufferedImage arrays and mix them. The shortest array will be played on loop
   * 
   * WARNIN: the images needs to has the same resolution
   * 
   * @param image -&gt; image mixed as background
   * @param image2 -&gt; image mixed as foreground
   * @return a mixed image array.
   */
  private BufferedImage[] mixingTwoImages(BufferedImage[] image, BufferedImage[] image2)
  {
    // checking no empty images.
    if (image.length == 0 || image2.length == 0) 
    {
      RuntimeException exception =
          new RuntimeException(""empty images"");
      LOG.log.log(Level.SEVERE, exception.getMessage(), exception);
      throw exception;
    }
    int width = Math.max(image[0].getWidth(), image2[0].getWidth());
    int height = Math.max(image[0].getHeight(), image2[0].getHeight());
    // creating a sequence of the longest size of them
    BufferedImage[] output = new BufferedImage[Math.max(image.length, image2.length)];
    for (int i = 0; i &lt; output.length; i++) // for each frame
    {
      // we create a frame
      output[i] = new BufferedImage(width, height, BufferedImage.TYPE_INT_ARGB);
      Graphics g = output[i].getGraphics();
      // mixing the frame 
      if (image.length &gt; image2.length) // if the first array is longer
      {
        g.drawImage(image[i], 0, 0, null);
        g.drawImage(image2[i % image2.length], 0, 0, null);
      } else if (image.length &lt; image2.length) // if the second array is longer
      {
        g.drawImage(image[i % image.length], 0, 0, null);
        g.drawImage(image2[i], 0, 0, null);
      } else // bot of the same size
      {
        g.drawImage(image[i], 0, 0, null);
        g.drawImage(image2[i], 0, 0, null);
      }
    }
    return output;
  }
</code></pre>
",https://stackoverflow.com/questions/47633191/unit-testing-a-complex-renderer-class-best-practices,"['java', 'testing', 'rendering', 'bufferedimage']",119,FALSE,0,0,No suggestions were provided
Best practices for testing a golang&#39;s Web apps query parameters,"<p>In a simple case of two required parameters, there are four possible test cases IIUC:</p>

<ol>
<li>both empty</li>
<li>first set but not second</li>
<li>second set but not first</li>
<li>both set</li>
</ol>

<p>What is best practice, test all four cases?</p>

<p>Because even testing the first and last cases is quite verbose in Golang:</p>

<pre><code>func TestGoodParameter(t *testing.T) {

        req, _ := http.NewRequest(""GET"", ""/"", nil)

        q := req.URL.Query()
        q.Add(""first"", ""foo"")
        q.Add(""second"", ""bar"")
        req.URL.RawQuery = q.Encode()

        rec := httptest.NewRecorder()
        root(rec, req)
        res := rec.Result()

        if res.StatusCode != http.StatusOK {
                t.Errorf(""got %v, expected %v"", res.StatusCode, http.StatusOK)
        }

}

func TestBadParameter(t *testing.T) {

        req, _ := http.NewRequest(""GET"", ""/"", nil)

        rec := httptest.NewRecorder()
        root(rec, req)
        res := rec.Result()

        if res.StatusCode != http.StatusBadRequest {
                t.Errorf(""got %v, expected %v"", res.StatusCode, http.StatusBadRequest)
        }

}
</code></pre>

<p>Or are there some tricks I am missing here? It obviously gets even more complicated when say there are five parameters where two of them are optional!</p>
",https://stackoverflow.com/questions/46211446/best-practices-for-testing-a-golangs-web-apps-query-parameters,"['testing', 'go']",7725,TRUE,3,1,No generalizable suggestion was provided
What to Assert in E2E Test Cases - Best Practices,"<p>I recently transferred to an existing (but new) project, still in beta, that already has a fair amount of unit, integration, and system / e2e tests. Presently, a large portion of integration and system tests are asserting equality between an <code>expected</code> JSON payload and the <code>actual</code> JSON payload.             </p>

<p>Considering the fast moving nature of this project (and that it's in beta), changes are often causing many tests to flip red, as they're changing the JSON payload. It seems redundant to frequently change <code>expected</code> JSON payload to match the new output, but I'll do it without complaining if I know that's the ideal way to test.      </p>

<p>My question (TLDR): <strong>In the case of a JSON API, if I am only testing ""Happy Path"" e2e / system test scenarios; what would be my ideal assertion statement?</strong> Am I looking to test the entire payload against an expected payload or would it make more sense to compare status codes, and maybe some high level JSON keys?</p>
",https://stackoverflow.com/questions/45925119/what-to-assert-in-e2e-test-cases-best-practices,"['testing', 'integration-testing', 'system-testing']",454,FALSE,3,0,No suggestions were provided
What are best practices for testing methods which call similar method of same class with different parameter types?,"<p>What is the best practice to test method, which calls similar method of same class with different parameter type?</p>

<p>Should an instance be mocked or no? Etc.</p>

<p>Have you examples or solution for current one?</p>

<p>I am in interested in best practice for cases, when tested method is more,
than 1 row and copying of tested code to test class is problematic.</p>

<pre><code>class A {
  Map z = //...
  public void put(String x, Y y) {
    z.put(x, y);
  }
  public void put(String x, String y) {
    put(x, Y.parse(y));
  }
}
</code></pre>
",https://stackoverflow.com/questions/45079882/what-are-best-practices-for-testing-methods-which-call-similar-method-of-same-cl,"['java', 'unit-testing', 'testing', 'junit', 'coding-style']",153,TRUE,1,1,No generalizable suggestion was provided
Best Practices for this TDD attempt,"<p>I code for about 12 years, but I've never get used to TDD in all this time.</p>

<p>Well, things are about to change, but since I'm learning all by myself, I hope you guys could help me.</p>

<p>I'm posting a game example for a VERY SIMPLE chest class.
When the player grabs a chest, it registers the current time it was obtained.
This chest takes some time to open so, I need, for UI reasons, to show the remaining time it takes to open.
Each chest has a type, and this type is bound to a database value of how much time it would take to open.</p>

<p>This is a ""no-testing-just-get-things-done-fast-mindset"". Consider that ChestsDatabase and DateManager are singletons containing the database-bound values and the current system time wrapped into a class.</p>

<pre><code>public class Chest {
    private readonly int _type;
    private readonly float _timeObtained;

    public Chest(int type, float timeObtained) {
        _type = type;
        _timeObtained = timeObtained;
    }

    public bool IsOpened() {
        return GetRemainingTime() &lt;= 0;
    }

    // It depends heavily on this concrete Singleton class
    public float GetRemainingTime() {
        return ChestsDatabase.Instance.GetTimeToOpen(_type) - GetPassedTime();
    }

    // It depends heavily on this concrete Singleton class
    private float GetPassedTime() {
        return DateManager.Instance.GetCurrentTime() - _timeObtained;
    }
}
</code></pre>

<p>Of course, I could have made it in a Dependency Injection fashion and get rid of the singletons:</p>

<pre><code>public class Chest {
    private readonly ChestsDatabase _chestsDatabase;
    private readonly DateManager _dateManager;
    private readonly int _type;
    private readonly float _timeObtained;

    public Chest(ChestsDatabase chestsDatabase, DateManager dateManager, int type, float timeObtained) {
        _chestsDatabase = chestsDatabase;
        _dateManager = dateManager;
        _type = type;
        _timeObtained = timeObtained;
    }

    public bool IsOpened() {
        return GetRemainingTime() &lt;= 0;
    }

    public float GetRemainingTime() {
        return _chestsDatabase.GetTimeToOpen(_type) - GetPassedTime();
    }

    private float GetPassedTime() {
        return _dateManager.GetCurrentTime() - _timeObtained;
    }
}
</code></pre>

<p>What if I use interfaces to express the same logic? This is going to be much more ""TDD-friendly"", right? (supposing that I've done the tests first, of course)</p>

<pre><code>public class Chest {
    private readonly IChestsDatabase _chestsDatabase;
    private readonly IDateManager _dateManager;
    private readonly int _type;
    private readonly float _timeObtained;

    public Chest(IChestsDatabase chestsDatabase, IDateManager dateManager, int type, float timeObtained) {
        _chestsDatabase = chestsDatabase;
        _dateManager = dateManager;
        _type = type;
        _timeObtained = timeObtained;
    }

    public bool IsOpened() {
        return GetRemainingTime() &lt;= 0;
    }

    public float GetRemainingTime() {
        return _chestsDatabase.GetTimeToOpen(_type) - GetPassedTime();
    }

    private float GetPassedTime() {
        return _dateManager.GetCurrentTime() - _timeObtained;
    }
}
</code></pre>

<p>But how the hell am I supposed to test something like that?
Would it be like this?</p>

<pre><code>    [Test]
    public void SomeTimeHavePassedAndReturnsRightValue()
    {
        var mockDatabase = new MockChestDatabase();
        mockDatabase.ForType(0, 5); // if Type is 0, then takes 5 seconds to open
        var mockManager = new MockDateManager();
        var chest = new Chest(mockDatabase, mockManager, 0, 6); // Got a type 0 chest at second 6
        mockManager.SetCurrentTime(8); // Now it is second 8
        Assert.AreEqual(3, chest.GetRemainingTime()); // Got the chest at second 6, now it is second 8, so it passed 2 seconds. We need 5 seconds to open this chest, so the remainingTime is 3
    }
</code></pre>

<p>Is this logically right? Am I missing something? Because this seems so big, so convoluted, so... wrong. I had to create 2 extra classes ~just~ for the purpose of these tests.</p>

<p>Let's see with a mocking framework:</p>

<pre><code>    [Test]
    public void SomeTimeHavePassedAndReturnsRightValue()
    {
        var mockDatabase = Substitute.For&lt;IChestsDatabase&gt;();
        mockDatabase.GetTimeToOpen(0).Returns(5);
        var mockManager = Substitute.For&lt;IDateManager&gt;();
        var chest = new Chest(mockDatabase, mockManager, 0, 6);
        mockManager.GetCurrentTime().Returns(8);
        Assert.AreEqual(3, chest.GetRemainingTime());
    }
</code></pre>

<p>I got rid of two classes with the framework, but still, I feel there's something wrong. Is there a simpler way in my logic? In this single case, would you use a mocking framework or implemented classes?</p>

<p>Would you guys get rid of the tests altogether or would you insist in any of my solutions? Or how to make this solution better?</p>

<p>Hope you can help me in my TDD journey. Thanks.</p>
",https://stackoverflow.com/questions/43603732/best-practices-for-this-tdd-attempt,"['testing', 'tdd']",80,TRUE,2,2,Advantages of TDD are discussed
Elasticsearch testing(unit/integration) best practices in C# using Nest,"<p>I've been seraching for a while how should I test my data access layer with not a lot of success. Let me list my concerns:</p>

<ol>
<li>Unit tests</li>
</ol>

<p>This guy (here: <a href=""https://stackoverflow.com/questions/38207159/using-inmemoryconnection-to-test-elasticsearch"">Using InMemoryConnection to test ElasticSearch</a>) says that:</p>

<blockquote>
  <p>Although asserting the serialized form of a request matches your
  expectations in the SUT may be sufficient.</p>
</blockquote>

<p>Does it really worth to assert the serialized form of requests? Do these kind of tests have any value? It doesn't seem likely to change a function that should not change the serialized request.</p>

<p>If it does worth it, what is the correct way to assert these reqests?</p>

<ol start=""2"">
<li>Unit tests once again</li>
</ol>

<p>Another guy (here: <a href=""https://stackoverflow.com/questions/36503930/elasticsearch-2-0-nest-unit-testing-with-moq"">ElasticSearch 2.0 Nest Unit Testing with MOQ</a>) shows a good looking example:</p>

<pre class=""lang-cs prettyprint-override""><code>void Main()
{
    var people = new List&lt;Person&gt;
    {
        new Person { Id = 1 },
        new Person { Id = 2 },
    };

    var mockSearchResponse = new Mock&lt;ISearchResponse&lt;Person&gt;&gt;();
    mockSearchResponse.Setup(x =&gt; x.Documents).Returns(people);

    var mockElasticClient = new Mock&lt;IElasticClient&gt;();
    mockElasticClient.Setup(x =&gt; x
        .Search(It.IsAny&lt;Func&lt;SearchDescriptor&lt;Person&gt;, ISearchRequest&gt;&gt;()))
        .Returns(mockSearchResponse.Object);

    var result = mockElasticClient.Object.Search&lt;Person&gt;(s =&gt; s);

    Assert.AreEqual(2, result.Documents.Count()).Dump();
}

public class Person
{
    public int Id { get; set;}
}
</code></pre>

<p>Probably I'm missing something but I can't see the point of this code snippet. First he mocks an <code>ISearchResponse</code> to always return the <code>people</code> list. then he mocks an <code>IElasticClient</code> to return this previous search response to any search request he makes.</p>

<p>Well it doesn't really surprise me the assertion is true after that. What is the point of these kind of tests?</p>

<ol start=""3"">
<li>Integration tests</li>
</ol>

<p>Integration tests do make more sense to me to test a data access layer. So after a little search i found this (<a href=""https://www.nuget.org/packages/elasticsearch-inside/"" rel=""noreferrer"">https://www.nuget.org/packages/elasticsearch-inside/</a>) package. If I'm not mistaken this is only about an embedded JVM and an ES. Is it a good practice to use it? Shouldn't I use my already running instance?</p>

<p>If anyone has good experience with testing that I didn't include I would happily hear those as well.</p>
",https://stackoverflow.com/questions/39305929/elasticsearch-testingunit-integration-best-practices-in-c-using-nest,"['testing', 'elasticsearch', 'nest']",5418,TRUE,10,1,All suggestions regarding unit and integration testing are specific to elasticsearch
Testing Symfony3 best practices,"<p>I would like to know which is the best technology for testing <code>Symfony</code> apps. My idea is to test all the <strong>Application layers</strong>, starting with the <strong>Database</strong> (repository and queries), the <strong>services</strong> , <strong>Controllers</strong> and <strong>Views</strong>. </p>

<p>I check about this but i'm not sure which direction to follow. I found out some tool like <code>Phpspec</code> and <code>Behat</code> but i'm not sure they fit my need and which one is the best... What do you guys suggest?</p>
",https://stackoverflow.com/questions/38792933/testing-symfony3-best-practices,"['testing', 'phpunit', 'symfony', 'behat', 'phpspec']",593,TRUE,1,1,Architecture of test suit is important
Golang test mock functions best practices,"<p>I am developing some tests for my code (using the <em>testing</em> package), and I am wondering what's the best way to mock functions inside the tested function:</p>

<p>Should I pass the function as parameter?
In that case, what if that function calls another function? Should I pass both the first and second function as parameters in the tested one?</p>

<p>Note: some of the functions are called on objects (i.e. someObj.Create()) and use HTTP API calls.</p>

<p>UPDATE for clarification:</p>

<p>Example: functions</p>

<pre><code>func f1() error {
  ... //some API call
}

func (s *SomeStruct) f2() error {
  return f1
}

func f3() error {
  return nil
}

func f4() error {
  ...
  err = obj.f2()
  ...
  err = f3()
  ...
}
</code></pre>

<p>For the above: if I want to test f4, what's the best way to mock f2 and f3?</p>

<p>If I pass f2 and f3 to f4 as parameters it would work, but then what for the f2 test? Should I pass f1 to f2 as parameter?</p>

<p>And if that's it, should then f4 have f1 as well in the parameters?</p>
",https://stackoverflow.com/questions/36688872/golang-test-mock-functions-best-practices,"['testing', 'go']",12155,TRUE,4,2,Mocking is discussed
Android Integration Test of a Distributed Application (best practices),"<p>I'm trying to write an integration test of my Android application. The application stores certain data at <strong>Google Cloud Datastore</strong> which are then being exchanged between different devices running the app.</p>

<p>And this is actually what I want to test - does the data exchange work fine? <strong>When one device saves piece of data to Datastore, does the other device(s) see(s)s it correctly, etc?</strong></p>

<p>I was checking various Android testing tools but none of them seems to be supporting this testing use-case. Most of the time I was playing with Robolectric to shadow all the unnecessary part of the app and test only what's necessary but I've got to several troubles:</p>

<ul>
<li>Robolectric seems not to be able to run multiple threads properly. As my app is sending data to Datastore in background threads, this is a main issue.</li>
<li>Robolectric seems to always run tests in a single JVM (let me know if I'm wrong here). As my app is using couple of static fields, it's not easy to simulate several devices and not to share this static fields. </li>
</ul>

<p><strong>Basically, I need to run the test on 2 (or more devices) at the same time when on each device different commands are executed but altogether they work seamlessly and correctly.</strong></p>

<p>I've solved this by </p>

<ul>
<li>bringing 'TestActivity' where I've implemented the test procedures for both of the devices; this activity UI has 2 buttons (Test A; Test B) which are both presented and by clicking on each of them at those 2 different devices, I'm able to run the test. </li>
<li>There was a small challenge with syncing those 2 devices but with a little effort I also solved this. </li>
<li>I also had to temporarily replace the main activity in AndroidManifest.xml with my TestActivity to present Test UI instead of the application UI.</li>
</ul>

<p><a href=""https://i.stack.imgur.com/uL5rW.png"" rel=""nofollow noreferrer""><img src=""https://i.stack.imgur.com/uL5rW.png"" alt=""enter image description here""></a></p>

<p>My questions are as follows.</p>

<ol>
<li>Is this approach correct? None of the existing Test frameworks support running of tests at 2 or more ""devices"" simultaneously? It does not have to be real android devices (or emulators), JVM would be enough (like Robolectric is doing). Just I need to test the complex distributed logic at more JVMs at the same time. Or at least simulate such a run (there are static fields in my app.)</li>
<li>How to keep such tests along with the main application? I had to implement couple of hacks into the app so the test has got access to internal structures (for test initialization and validation). I also had to implement the TestActivity and put it as the main activity. I don't want to check in these changes and build my main app as they will remain there. I have realized that an app (apk) cannot depend on another apk (the test application would depend on the main application and only would bring some additional functionality the test needs); apk can only depend on a library (aar). Does it mean my only option is to create an aar from my current apk and then bring 2 apks - one is the main one (which would probably contain nothing, just AndroidManifest.xml) and the other one would implement the test; both of the apks would be dependent on my aar?</li>
</ol>
",https://stackoverflow.com/questions/35502891/android-integration-test-of-a-distributed-application-best-practices,"['android', 'testing', 'automated-tests', 'integration-testing', 'distributed-system']",141,FALSE,1,0,No suggestions were provided
Using @FindBy to find an element. Refactoring and best practices,"<p>I currently have this method in my selenium framework.</p>

<pre><code>public void selectAddProductButton() {
    driver.findElement(By.id(""Content"")).findElement(By.className(""Title"")).findElement(By.tagName(""a"")).click();
}
</code></pre>

<p>However, I like it and I don't like it. I feel like this is a dirty way to approaching this. I thought it would be better to use @FindBy but I don't see how I could. I've read online that I can achieve this by using the @FindBy with an xpath. However, I've also read that using xpath this way is a bad practice. Is there a better way I can do this? I usually use @FindBy for more simple things. An example would be </p>

<pre><code>@FindBy(id = ""firstname"")
private WebElement firstName;
</code></pre>

<p>I don't think there is a way to find an element that is nested within other elements  using @FindBy unless I used xpath</p>
",https://stackoverflow.com/questions/31122631/using-findby-to-find-an-element-refactoring-and-best-practices,"['java', 'selenium', 'testing', 'xpath', 'selenium-webdriver']",1086,TRUE,4,1,No generalizable suggestion was provided
Best practices for implementing Page Object model for pages with many elements,"<p>I'm implementing Page Object model with Page Object factory and struggling to figure out the best way to handle pages with many elements. Page Object gets ugly when you have several checkboxes and want to create several methods for each of them. Let's say I have a page with checkbox1... checkboxN. For each of those elemements I want to have methods like isEnabled, isDisplayed, isChecked. If I implement it as it's suggested, I'll end up with 3xN methods like isCheckbox1Enabled, etc.</p>

<p>What is the best practice here? Should I provide simple get methods for those elements? Should I create map and single instance of each method like isCheckboxEnabled(String checkboxName)?</p>

<p>I don't like aproach with the map because then I have to know checkbox name inside my test...</p>

<p>Thanks!</p>
",https://stackoverflow.com/questions/31038924/best-practices-for-implementing-page-object-model-for-pages-with-many-elements,"['testing', 'selenium-webdriver', 'webdriver', 'ui-automation', 'pageobjects']",1175,FALSE,1,1,Suggestions were page object specific
Regarding unit testing best practices,"<p>I have been tasked with testing an existing application, and I've done so with my own in the past, but I am a little unsure of whether I am using the right approach.</p>

<p>Let's say I have the following example:</p>

<p>Class <code>users</code> has a function called <code>getAll()</code> which returns the list of users by querying the database. There are (as far as I can tell) two straightforward ways to test this functionality:</p>

<ul>
<li><p>Use the same query code that the <code>getAll()</code> function uses, independently in the unit test. Then, perform the <code>getAll()</code> call and assert the results. </p></li>
<li><p>Have a data provider give the unit test data that is of the format that is expected, hard-coded to values we know are contained in the database. For example, we would pass a hard-coded array containing all users in the format the the <code>getAll()</code> function expects, and assert the results.</p></li>
</ul>

<p>Although the second approach seems more in line with testing, it has the added results of adding a layer of security risk. Anyone with access to the test suite would also have plaintext access to a lot of potentially sensitive data. On top of that, depending on database size queries like the above could make the tests ridiculously long for very little reason.</p>

<p>Which would be the preferred approach?</p>
",https://stackoverflow.com/questions/28589382/regarding-unit-testing-best-practices,"['unit-testing', 'testing', 'automated-tests']",62,FALSE,-1,1,No suggestions were provided
