title,body,link,tags,view_count,is_answered,score,answer_count,critical points
Is good practice implement tests to validate tests automation it self?,"<p>I want to know input about the next subject:</p>
<p>Is it usual and/or good practice to implement tests that will be testing automation tests, i.e., I have a test automation project over an API project and want to know if I should create unity tests to apply to my test automation code, or this is overloading work and unnecessary? In advanced I want to thanks for all the help.</p>
",https://stackoverflow.com/questions/73414138/is-good-practice-implement-tests-to-validate-tests-automation-it-self,"['unity-game-engine', 'testing', 'automation']",20,FALSE,0,1,"The question is about testing the automation tool. The suggestion says that depending on the size of the project, it is a viable option"
Is it good practice to just test that components don&#39;t throw?,"<p>This might be a ridiculous question, but I'm just learning testing and wondering if the following test, repeated throughout a react native app, would actually be worth implementing. I'm using jest with react native testing library.</p>
<pre><code>it('renders properly', () =&gt; {
  const component = render(&lt;SomeScreen /&gt;)
  expect(component).not.toThrow()
})
</code></pre>
<p>Where <code>&lt;SomeScreen /&gt;</code> is a screen in the app... It is not supposed to throw... This would not be shallowly rendered so most of the children would be included, though some things will be mocked where necessary.</p>
<p>If this is implemented to run on every pull request, would this actually provide any value?</p>
<p>Is something like this considered good/bad practice? It seems too simple, but is essentially what I've been asked to do.</p>
",https://stackoverflow.com/questions/72422085/is-it-good-practice-to-just-test-that-components-dont-throw,"['reactjs', 'react-native', 'testing', 'jestjs', 'react-testing-library']",174,TRUE,0,1,"The answer is question and react-native specific, doesn't add to the research"
Does loading multiple json files in single test suit is a good practice in cypress?,"<p>Does loading multiple json files in single test suit is a good practice in cypress?
Something like this:</p>
<pre><code>before(() =&gt; {
    cy.fixture('productCatalogData').then((datajson) =&gt; {
      recipeData = datajson.recipes;
      return recipeData;
    });
    cy.fixture('loginData').then((datajson) =&gt; {
      loginData = datajson;
      return loginData;
    });
  });
</code></pre>
",https://stackoverflow.com/questions/71051477/does-loading-multiple-json-files-in-single-test-suit-is-a-good-practice-in-cypre,"['javascript', 'testing', 'cypress']",551,FALSE,0,1,It is okay to load multiple files for testing as long they don't change the database of the main program is created in the test environment
Is it a good practice to include some data for doing a test?,"<p>I have never did unit testing or integration testing and would like to learn the good way (but keeping things simple since I am a newcomer).
Here is my problem: I want to offer a test for a function that manipulates and exports some files (that unzip: imbricated zip file). Should I provide a minimal data example with the test (as I explain after)? If not what would you do?</p>
<p>I created:</p>
<ul>
<li>a &quot;tests&quot; directory inside my utilities subpackage</li>
<li>a &quot;data&quot; directory in my tests subpackage</li>
<li>a dummy  (almost empty for test purpose) zip file called zip_root.zip and structured as follow: {zip_root.zip:{zip_child1:{zip_child1_grandchild1:file_child1_grandchild.txt},zip_child2:file_child2.txt} in &quot;tests/data/input/zip&quot; directory</li>
<li>a &quot;tests/data/output/unzip&quot; empty directory</li>
<li>a test file &quot;test_extract.py&quot; in tests subpackage</li>
<li>the target module &quot;extract_zip.py&quot;</li>
</ul>
<p>Below are the target module &quot;extract_zip.py&quot; and test file code (if needed and allowed by SO I can provide the whole package).</p>
<p><strong>extract_zip.py:</strong></p>
<pre><code>'''
walk a file tree from specified starting point, unzip any zip files encountered in the
directory where zip file was found, and then delete the zip file after succesfully
unzipping
'''
import zipfile, os, glob
import shutil
 
def extract_zip(zippedfilepath,toFolder):
    with zipfile.ZipFile(zippedfilepath, 'r') as zfile:
        #print(&quot;Extracting {}&quot;.format(zippedfilepath))
        zfile.extractall(path=toFolder)
 
def extract_nested_zip(zipped_file, toFolder):
    &quot;&quot;&quot; Extract a zip file including any nested zip files
        Delete the zip file(s) after extraction
    &quot;&quot;&quot;
    extract_zip(zipped_file,toFolder)
    basename = os.path.basename(zipped_file).split('.zip')[0]
    path = list(glob.iglob(os.path.join(toFolder,basename,'**/*.zip'), recursive=True))
    for filepath in path:
        extract_nested_zip(filepath, os.path.dirname(filepath))
        os.remove(filepath)
 
if __name__ == &quot;__main__&quot;:
    rootpath = r&quot;datalib/utilities/tests/data&quot;
    zippedFile = os.path.join(rootpath,r'input/zip/zip_root.zip')
    toFolder= os.path.join(rootpath,r'output/unzip')
    extract_nested_zip(zippedFile, toFolder)
</code></pre>
<p><strong>test_extract_zip.py</strong></p>
<pre><code>from ..extract_zip import extract_zip
import os
import tempfile
 
def test_extract_zip():
    rootpath = r&quot;datalib\utilities\tests\data&quot;
    zippedfilepath = os.path.join(rootpath,r&quot;input\zip\zip_root.zip&quot;)
    with tempfile.TemporaryDirectory() as tmpdir:
        toFolder =tmpdir
        extract_zip(zippedfilepath,toFolder)
        #import pdb;pdb.set_trace()
        assert os.listdir(toFolder)==['zip_root']
</code></pre>
<p>Here is an image of the hierarchy to clear the organization:
<a href=""https://i.stack.imgur.com/IUDdo.png"" rel=""nofollow noreferrer""><img src=""https://i.stack.imgur.com/IUDdo.png"" alt=""enter image description here"" /></a></p>
<p>Remark: I am not familiar with simple test practice. I used to make my test inside the targeted module below the <code>if __name__ = &quot;__main__&quot;</code> but I am not sure it is really good practice.</p>
",https://stackoverflow.com/questions/66011629/is-it-a-good-practice-to-include-some-data-for-doing-a-test,"['python', 'unit-testing', 'testing']",190,FALSE,2,0,To separate the data used for testing and for the main application. Create separate folders/packages/directory and an alternate test environment
Is it considered good practice using too many factories in pytest?,"<p>I am trying to write tests for Django/DjangoREST project. I have decided to use pytest. I have poor experience in writing tests for Django projects specifically. So I am confused now.</p>
<p>Here is an example:</p>
<pre><code>@pytest.mark.django_db
def test_some_view(
    api_client,
    simple_user,
    model1_factory,
    model2_factory,
    ...  # many other model factories
    modelN_factory
):
    # ...
    # creating here other objects that really depends on each other
    # ...
    model2_obj = ...   # model2 object on its own side depends on model3, model4... and so on

    model1_objs = []
    for i in range(10):
        model1_objs.append(model1_factory(some_field=100, some_model2_rel=model2_obj)
    assert len(model1_objs) == 1, &quot;Created items with duplicate `some_field`&quot;
</code></pre>
<p>As you can see I have too many factories to be used in one test. But looking
at my model structure right now, I can't think of a better way. Is it ok to use so many
factories for one test? Or should I find some issues related to my tables' relations?</p>
<p>Any help is appreciated. Thanks in advance</p>
",https://stackoverflow.com/questions/64297337/is-it-considered-good-practice-using-too-many-factories-in-pytest,"['django', 'testing', 'django-rest-framework', 'pytest', 'factory-boy']",1102,TRUE,1,1,"Create separate test environement, use factories to produce real-like object instances. Try to keep it simple"
What is a &quot;good practice&quot; approach to including long running tests as part of CI?,"<p>Our current CI setup is a typical one: for each PR made to our main Git repo, we have a Jenkins on which do a build + test, and after passing those and code reviews, we merge. This takes about an hour per PR.</p>
<p>I'm trying to find a reasonable way to automate a stage of testing process we run after our CI (performance testing) and we currently run on demand, manually. These are long running tests that should take around 20 hours to run so running them for each PR would slow us down.</p>
<p>So that means we might want to run them separately from our current CI, perhaps once per day. However, this doesn't seem like a good solution either since it will be hard to maintain. Say PRs <code>A</code>, <code>B</code> and <code>C</code> get merged in after passing CI but <code>B</code> contains a change that will cause a performance slow down. We will find out about this 24 hours later and then have to figure out which commit out of the 3 caused the issue. So let's say this takes use at least one day and find the fix for, <code>B*</code>. But by then, 2 more PRs <code>D</code>, <code>E</code> have been merged. So we have <code>A - B - C - D - E - B*</code>, which ideally should run and fix the original issue caused by <code>B</code>.</p>
<p>But what if <code>D</code> introduced another performance slow down? How would we tell if <code>B*</code> worked? Now we have an even bigger group of PRs we need to look through for the issue! It seems like merging PRs in before it passes these tests isn't a good idea. But that brings us back to the first idea, which is too slow.</p>
<p>How do people usually automate long running tests as part of their workflow?</p>
",https://stackoverflow.com/questions/64094089/what-is-a-good-practice-approach-to-including-long-running-tests-as-part-of-ci,"['testing', 'continuous-integration', 'automated-tests', 'devops', 'performance-testing']",55,FALSE,1,0,No suggestions made
good practice for testing mocked object,"<p>It is good practise to match mock objects widely but verify them precisely.
for example:</p>
<p>Using this:</p>
<pre><code>when(myMock.has(any())).thenReturn(myValue);
</code></pre>
<p>Rather than:</p>
<pre><code>when(myMock.has(eq(&quot;blah&quot;)).thenReturn(myValue);
</code></pre>
<p>Along with:</p>
<pre><code>var result = myMethod();
assertThat(result, is(myValue));
</code></pre>
<p>Because it is making sure that it is always returned <code>myValue</code> regardless of the <code>has</code> method input.</p>
<p>There was a good explanation for this rule but I can not find it.
something along the lines: <code>match widely and verify precisely</code>.</p>
<p>It would be great if you can advise me about the name of the rule or some reference to it?</p>
",https://stackoverflow.com/questions/63354879/good-practice-for-testing-mocked-object,"['java', 'testing', 'mocking', 'coding-style']",55,FALSE,-1,1,When mocking it is easier to map the input to a wide variety of inputs while matching the output specifically in order to avoid difficult debugging sessions where you're trying to debug the test case and not the code itself. Specific input test cases can be creates when trying to test a special input
Is it a good practice to include generated classes into managed test folder?,"<p>I have a code which relies on generated thrift and protobuf classes by code-user (that's a library). </p>

<p>I want to test it using my own generated thrift and protobuf classes (they, probably, will not change very often). So, for that i can include dependencies for <code>build.gradle</code> to be able to generate them. The problem occurs if i want to do the same in CI, because i have to install thrift and protobuf compilers on building machine.</p>

<p>I can avoid this if i generate all classes for testing using my pc, for example, and include them in test-source code. </p>

<p>The main question: is it a good or acceptable practice or i should prefer to re-generate each time these classes?</p>
",https://stackoverflow.com/questions/58493651/is-it-a-good-practice-to-include-generated-classes-into-managed-test-folder,"['java', 'testing', 'protocol-buffers', 'code-generation', 'thrift']",273,TRUE,0,1,It is better to regenerate auto-generated code everytime you run instead of pushing them to the source
Is RESTful API functional testing with pytest possible/a good practice?,"<p>I am still a novice programmer and I cannot get my head around how to properly test a RESTful API. I already implemented some unit tests that test each endpoint individually, I would like some tests that test several API endpoints calls in sequence in the same test. Would that be a functional test? Is it usually a common practice? Thanks!</p>
",https://stackoverflow.com/questions/57394355/is-restful-api-functional-testing-with-pytest-possible-a-good-practice,"['python', 'api', 'testing', 'pytest', 'functional-testing']",210,TRUE,0,1,Selenium is suggested as a good functional testing tool
Is a good practice looping a test?,"<p>I am having a test that checks the response from an API route, but basically more of the same kind of routes will be added.</p>

<p>The routes only change like this:</p>

<ol>
<li>/example/route/<code>red</code></li>
<li>/example/route/<code>green</code></li>
</ol>

<p>I am creating an array of strings:</p>

<pre><code>const ending = [
 ""red"",
 ""green""
]
</code></pre>

<p>Then I loop into the array and use the same <code>describe</code> method to test this functionality</p>

<pre><code>ending.forEach(end =&gt; {
  describe(`${end} routes`, () =&gt; {
    // My test goes here  
  }
}
</code></pre>

<p>Is working, but the question is if this is a good practice in testing?</p>

<p>Or if this could cause an unexpected behaviour later?</p>

<p>Thanks!</p>
",https://stackoverflow.com/questions/57059869/is-a-good-practice-looping-a-test,"['javascript', 'testing', 'ecmascript-6', 'mocha.js', 'chai']",46,FALSE,1,0,Be careful when you're looping over values in your test cases
is it a good practice to create Independent tests?,"<p>I have read in multiple blogs that we should keep our automation tests independent, for example: <a href=""https://www.thoughtworks.com/insights/blog/5-reasons-why-test-automation-can-fail"" rel=""nofollow noreferrer"">https://www.thoughtworks.com/insights/blog/5-reasons-why-test-automation-can-fail</a>
What I mean by independent is that each test should create and cleanup its own data and not rely on tests in other groups to create data.
Then in which scenarios should we use the dependsOnGroups annotation from TestNG, considering that the tests in the group could be spread across multiple classes and they will no longer be independent.</p>
",https://stackoverflow.com/questions/55307120/is-it-a-good-practice-to-create-independent-tests,"['java', 'testing', 'automated-tests']",78,FALSE,1,0,Is it good practice in creating independent test cases? Cases where creation and deletion of data related to the test is independent of any other test case and the entire application
Is it a good practice to use use the same httptest server for multiple methods,"<p>I am trying to test some golang code and I have a method that calls several other methods from its body. All these methods perform some kind of operations using an elastic search client. I wanted to know whether  it will be a good practice if I used a test server for testing this method that will write different responses depending upon the request method and path it received from the request that is made when the methods inside the body execute and make calls to the elasticsearch client that sends the requests to my test server?</p>

<p><strong>Update:</strong></p>

<p>I am testing an elasticsearch middleware. It implements a reindex service like this</p>

<pre><code>type reindexService interface {
    reindex(ctx context.Context, index string, mappings, settings map[string]interface{}, includes, excludes, types []string) error
    mappingsOf(ctx context.Context, index string) (map[string]interface{}, error)
    settingsOf(ctx context.Context, index string) (map[string]interface{}, error)
    aliasesOf(ctx context.Context, index string) ([]string, error)
    createIndex(ctx context.Context, name string, body map[string]interface{}) error
    deleteIndex(ctx context.Context, name string) error
    setAlias(ctx context.Context, index string, aliases ...string) error
    getIndicesByAlias(ctx context.Context, alias string) ([]string, error)
}

</code></pre>

<p>I can easily test all the methods using this pattern. Creating a simple elastic search client using a httptest server url and making requests to that server</p>

<pre><code>var createIndexTests = []struct {
    setup *ServerSetup
    index string
    err   string
}{
    {
        &amp;ServerSetup{
            Method:   ""PUT"",
            Path:     ""/test"",
            Body:     `null`,
            Response: `{""acknowledged"": true, ""shards_acknowledged"": true, ""index"": ""test""}`,
        },
        ""test"",
        """",
    },
   // More test cases here
}

func TestCreateIndex(t *testing.T) {
    for _, tt := range createIndexTests {
        t.Run(""Should successfully create index with a valid setup"", func(t *testing.T) {
            ctx := context.Background()
            ts := buildTestServer(t, tt.setup)
            defer ts.Close()
            es, _ := newTestClient(ts.URL)
            err := es.createIndex(ctx, tt.index, nil)
            if !compareErrs(tt.err, err) {
                t.Fatalf(""Index creation should have failed with error: %v got: %v instead\n"", tt.err, err)
            }
        })
    }
}
</code></pre>

<p>But in case of <code>reindex</code> method this approach poses a problem since reindex makes calls to all the other methods inside its body. reindex looks something like this:</p>

<pre><code>func (es *elasticsearch) reindex(ctx context.Context, indexName string, mappings, settings map[string]interface{}, includes, excludes, types []string) error {
    var err error

    // Some preflight checks

    // If mappings are not passed, we fetch the mappings of the old index.
    if mappings == nil {
        mappings, err = es.mappingsOf(ctx, indexName)
        // handle err
    }

    // If settings are not passed, we fetch the settings of the old index.
    if settings == nil {
        settings, err = es.settingsOf(ctx, indexName)
        // handle err
    }

    // Setup the destination index prior to running the _reindex action.
    body := make(map[string]interface{})
    body[""mappings""] = mappings
    body[""settings""] = settings

    newIndexName, err := reindexedName(indexName)
    // handle err

    err = es.createIndex(ctx, newIndexName, body)
    // handle err

    // Some additional operations

    // Reindex action.
    _, err = es.client.Reindex().
        Body(reindexBody).
        Do(ctx)
    // handle err

    // Fetch all the aliases of old index
    aliases, err := es.aliasesOf(ctx, indexName)
    // handle err
    aliases = append(aliases, indexName)

    // Delete old index
    err = es.deleteIndex(ctx, indexName)
    // handle err

    // Set aliases of old index to the new index.
    err = es.setAlias(ctx, newIndexName, aliases...)
    // handle err

    return nil
}
</code></pre>

<p>For testing the reindex method I have tried mocking and DI but that turns out to be hard since the methods are defined on a struct instead of passing an interface as an argument to them. (So now I want to keep the implementation same since it would require making changes to all the plugin implementations and I want to avoid that)</p>

<p>I wanted to know whether I can use a modified version of my build server funtion (the one I am using is given below) to return responses for different methods for the reindex service which will write the appropriate responses based on the HTTP method and the request path that is used by that method?</p>

<pre><code>
type ServerSetup struct {
    Method, Path, Body, Response string
    HTTPStatus                   int
}

// This function is a modified version of: https://github.com/github/vulcanizer/blob/master/es_test.go
func buildTestServer(t *testing.T, setup *ServerSetup) *httptest.Server {
    handlerFunc := http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
        requestBytes, _ := ioutil.ReadAll(r.Body)
        requestBody := string(requestBytes)

        matched := false
        if r.Method == setup.Method &amp;&amp; r.URL.EscapedPath() == setup.Path &amp;&amp; requestBody == setup.Body {
            matched = true
            if setup.HTTPStatus == 0 {
                w.WriteHeader(http.StatusOK)
            } else {
                w.WriteHeader(setup.HTTPStatus)
            }
            _, err := w.Write([]byte(setup.Response))
            if err != nil {
                t.Fatalf(""Unable to write test server response: %v"", err)
            }
        }

        // TODO: remove before pushing
        /*if !reflect.DeepEqual(r.URL.EscapedPath(), setup.Path) {
            t.Fatalf(""wanted: %s got: %s\n"", setup.Path, r.URL.EscapedPath())
        }*/
        if !matched {
            t.Fatalf(""No requests matched setup. Got method %s, Path %s, body %s\n"", r.Method, r.URL.EscapedPath(), requestBody)
        }
    })

    return httptest.NewServer(handlerFunc)
}
</code></pre>

<p>Something like this function but it takes a map of request methods and past mapped to appropriate responses and writes them to the writer?</p>
",https://stackoverflow.com/questions/55221261/is-it-a-good-practice-to-use-use-the-same-httptest-server-for-multiple-methods,"['go', 'testing']",629,FALSE,0,0,No suggestions made
Is it a good practice to assign atributes to the tester class that will be used by other tests,"<p>I'm writing unit tests for my python app with pytest.</p>

<p>The module I'm testing has many methods that will be called in sequence and their returns are to be used as arguments to the other ones. In short what I have is something like this:</p>

<pre><code>def foo_1():
    #load file and do stuff
    return bar_1

def foo_2(arg1):
    #do stuff with arg1
    return bar_2

def foo_3(arg1, arg2):
    #do stuff with arg1 and arg2
    return bar_3

x = foo_1()
y = foo_2(x)
z = foo_3(x,y)
</code></pre>

<p>Pretty basic stuff, and this are the tests I'm running:</p>

<pre><code>import foo_app

class TestClass:

    def test_foo_1(self):
        self.x = foo_app.foo_1()

        #never mind the assertions
        assert 0 == self.x

    def test_foo_2(self):
        self.y = foo_app.foo_2(self.x)

        #never mind the assertions
        assert 1 == self.y

    def test_foo_3(self):
        self.z = foo_app.foo_3(self.x, self.y)

        #never mind the assertions
        assert 3 == self.z
</code></pre>

<p>However, I'd like to know if this is a good practice on unit testing, and if not what is the best way to deal with this kind of scenario where I depend on the executions of previous methods to achieve my result?</p>
",https://stackoverflow.com/questions/54155709/is-it-a-good-practice-to-assign-atributes-to-the-tester-class-that-will-be-used,"['python', 'unit-testing', 'testing', 'pytest']",36,FALSE,-1,1,Ordering of test cases is important when loading or querying from other files or databases
Is it a good practice to unit test asynchronous code?,"<p>It is definitely possible to test asynchronous code by letting the thread wait until the asynchronous code finishes. However, is it encouraged to test asynchronous code. Or instead, should we seperate the logic and only test the synchronous part?</p>

<p>For example, in my app I would make a REST API call to fetch json from server and then I need to parse the json.</p>

<p>There are two approaches:</p>

<ol>
<li><p>Test the fetching and parsing as a whole. We can use <code>MockWebServer</code> to simulate timeout and response. </p>

<p>-Cons: it would bring some complexity.</p></li>
<li><p>Just test the parsing part, since we cannot control the API call part; it is controlled by <code>okhttp</code></p>

<p>--Cons: Hard to cover timeout case.</p></li>
</ol>
",https://stackoverflow.com/questions/54120306/is-it-a-good-practice-to-unit-test-asynchronous-code,"['java', 'android', 'testing']",282,TRUE,2,2,Use white box testing to test asynchronous code to verify the async call. Don't try to test asynchronous code through unit testing
Good practice with Mockito And BufferedReader,"<p>I'm trying to test a class that makes File/Stream treatment. For instance, the method <code>readFile</code> will use <code>BufferedReader</code> to return an <code>ArrayList</code> of String with every lines of the file inside: </p>

<pre><code>public ArrayList&lt;String&gt; readFile(String fileName)
{
    ArrayList&lt;String&gt; result = new ArrayList&lt;String&gt;();
    FileReader fr = null;
    BufferedReader br = null;
    try {

        fr = new FileReader(STORAGE_DIRECTORY+fileName);
        br = new BufferedReader(fr);
        String sCurrentLine;

        while ((sCurrentLine = br.readLine()) != null) {
            result.add(sCurrentLine);
        }
    }
        catch (FileNotFoundException e) {


            return new ArrayList&lt;String&gt;();
        } catch (IOException e) {

            return new ArrayList&lt;String&gt;();
        }

        br.close();
        fr.close();


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

<p>But when I use Mockito in order to mock <code>bufferedReader</code> method ""readLine()"",a <code>FileNotFoundException</code> is thrown because of <code>FileReader</code> constructor. Must I use <code>temporaryFile</code> or Mock <code>FileReader</code> constructor ?</p>

<pre><code>@Test
public void readFileTest5() throws Exception {
    BufferedReader bufferedReader = Mockito.mock(BufferedReader.class);
    FileReader fileReader = Mockito.mock(FileReader.class);
    when(BufferedReader.readLine()).thenReturn(""abc"");
    assertEquals("""",new ArrayList&lt;String&gt;(), FileUtil.readFile(""abc""));
}
</code></pre>

<p>Thank you</p>
",https://stackoverflow.com/questions/45839174/good-practice-with-mockito-and-bufferedreader,"['java', 'unit-testing', 'testing', 'mockito']",5843,TRUE,3,2,"Sematics of using mockito on buffered readers, irrelevant for this research"
"Starting TDD halfway a project, good practice?","<p>I am halfway in the development of a large Flask web application.</p>

<p>Back in the beginning I chose not to use test-driven-development, for learning curve vs project deadline reasons.</p>

<p>Thus these last weeks I had the opportunity to learn more about it, and I am quite exited about starting to use it.</p>

<p>However, regarding I didn't wrap my project with TDD from the start, is there any cons of starting to use it now ?</p>

<p>I would not refactor my entire app, only the new features I am going to design in the near future.</p>
",https://stackoverflow.com/questions/45169563/starting-tdd-halfway-a-project-good-practice,"['python', 'unit-testing', 'testing', 'tdd']",150,TRUE,3,3,TDD is recommended 
Development only with testing - no actually running - good practice?,"<p>I just started in a new team. My task right now is to bring an old application to their new microservice framework (mostly Java). It runs in quite a complex environment, like consuming other web services, messaging via several queues, and providing an public API for other services to use.</p>

<p>The new thing for me is that their development process doesn't involve an actually running the application even once. Instead they solely do testing: unit tests and integration tests. For the integration tests they employ a couple of docker container that mimic their actual production system. There is no staging system - only the production system, where I have no access.</p>

<p>To me it feels weird to never actually run the application. <strong>Is this common? Have you guys encountered the same? Is this considered a good practice?</strong></p>

<p><strong>Edit</strong>: For the system it is not critical that it runs 24/7 without interruption. An outage after a new deployment is not nice but if monitored and handled (e.g. switch back to an older version) it's not a big problem.</p>
",https://stackoverflow.com/questions/44502012/development-only-with-testing-no-actually-running-good-practice,"['java', 'testing']",37,FALSE,0,0,No suggestions made
Pytest - Good practice for reading Excel &amp; SQL,"<p>I have a python application that data mines a number of server folders to extract Excel files that contain a specific cell.  From these Excel files, a SQL database is populated each month with the data from the Excel files, the files are updated on a regular basis and the database contains a monthly snapshot.</p>

<p>After the monthly snapshot, a graph is printed for each Excel file, using matplotlib, showing the trends over the past 12 months.</p>

<p>The application works fine at the moment but I would like to add some tests using pytest.</p>

<p>Now, is it best practice to create a sample Excel file and SQL database to run the tests against as this will provide me with some way of checking that the test results are run against consistent data, or is it typical to run tests against the live data?</p>

<p>Secondly, how do I test pytest to use sample data when running a test, leaving my application to use the real data the rest of the time?</p>
",https://stackoverflow.com/questions/43610960/pytest-good-practice-for-reading-excel-sql,"['python', 'python-3.x', 'testing', 'pytest']",424,FALSE,0,0,No suggestions made
"Calling Mongoose schema methods from a different schema, is this good practice?","<p>I know that it is possible to do this, but my question is whether there is a good reason not to do it, or is there a better way? I feel like it could make the code easier to follow and potentially make testing easier, but that's as far as I've gotten.</p>

<p>Example Code:</p>

<pre><code>postSchema.methods.publishPost = function(data, cb) {
  var self = this,
    options = options || {};

  mongoose.model('Version').findById(data.version).exec(function(err, version) {
    if (err) return cb(err);

    mongoose.model('Translation').findTranslatedVersion(version, function(err, translation) {
      if(err) return cb(err);

      publisher.publish(self, translation ? translation : version, function(err, published) {
        if (err) return cb(err);
        self.save(published);
      });
    });
  });
}
</code></pre>
",https://stackoverflow.com/questions/41726771/calling-mongoose-schema-methods-from-a-different-schema-is-this-good-practice,"['node.js', 'mongodb', 'testing', 'mongoose']",95,FALSE,1,0,No suggestions made
Is it good practice to write a test that waits for 31 mins to cover expiration scenarios?,"<p>I've written the ff. behavior test. Is writing a test that waits for 31 mins to cover expiration scenarios acceptable and good practice?</p>

<pre><code>public class ExpiredTokenBehaviorTestCase extends ActivityInstrumentationTestCase2&lt;ResetPasswordActivity&gt; {

    protected Solo solo;

    public final static int TOKEN_EXPIRATION_MINS = 31 * 1000 * 60; // 31 minutes, sanity check, can't do math

    public ExpiredTokenBehaviorTestCase() {
        super(ResetPasswordActivity.class);
    }

    @Override
    protected void setUp() throws Exception {
        solo = new Solo(getInstrumentation(), getActivity());
    }

    @Override
    protected void tearDown() throws Exception {
        solo.finishOpenedActivities();
    }

    /**
     * Expired
     */
    public void testExpiredPassword() {
        solo.typeText(0, ""+639224424166""); // type in mobile number to send the verification code
        solo.clickOnButton(""Next &gt;""); // click next

        if (solo.waitForActivity(VerificationActivity.class)) {
            solo.typeText(0, ""ab2f1de""); // valid code
            solo.sleep(TOKEN_EXPIRATION_MINS); // wait for token to expire
            solo.clickOnButton(""Next &gt;""); // now click on next
            solo.waitForText(""Verification code expired""); // should show the code expired
        }
    }

}
</code></pre>
",https://stackoverflow.com/questions/38885101/is-it-good-practice-to-write-a-test-that-waits-for-31-mins-to-cover-expiration-s,"['android', 'testing', 'automated-tests', 'robotium']",53,TRUE,0,1,"When dealing with expiration tags/tokens and testing them, manipulating the tags/tokens during testing is acceptable to speed up the runtime of the tests"
Is it a good practice to include an expected result in a testcase?,"<p>Consider the following test: </p>

<pre><code>    [TestCase(2016, true)]
    [TestCase(2017, false)]
    [TestCase(2018, false)]
    [TestCase(2019, false)]
    [TestCase(2020, true)]
    public void When_IsLeapYear_ReturnTrueForLeapYear(int year, bool expectedResult)
    {
        //Act
        var result = _sut.IsLeapYear(year);

        //Assert
        Assert.AreEqual(result, expectedResult);
    }
</code></pre>

<p>Is it a bad practice to include both the year and the expected results in testcases like that, instead of creating two different tests (e.g. one for expecting true, one for expecting false?)</p>

<p>Thanks</p>
",https://stackoverflow.com/questions/34778480/is-it-a-good-practice-to-include-an-expected-result-in-a-testcase,"['unit-testing', 'testing', 'tdd', 'nunit']",91,TRUE,4,1,It is not required to duplicate test code when looking for positive/negative test case on the same input (differing by one factor)
Is it a good practice to check the state of a database in acceptance tests?,"<p>Consider that one is supposed to write automated acceptance tests for e-commerce system. For example, you want to check that when customer completes checkout operation he has a new order registered in the system that is linked to his account. Now one thing, of course, that you can check is that there are some UI messages displayed like 'Order completed succesfully'. However that does not guarantee that the order is in fact persisted in the db. My question is whether it is OK to additionally verify with querying the DB that order indeed was saved. Or should I verify that inexplicitly in other acceptance test e.g. by checking list of orders (which should not be empty after completing checkout operation succesfully) beforehand performing checkout operation?</p>
",https://stackoverflow.com/questions/31942383/is-it-a-good-practice-to-check-the-state-of-a-database-in-acceptance-tests,"['testing', 'language-agnostic', 'acceptance-testing']",649,TRUE,1,1,"When performing acceptance testing, it would be a good idea to check the database for its validity and integrity. When using automated tools such as selenium, suggested data-validation options on the database are available. The acceptance criteria should be precise and unambiguous"
