mercredi 2 août 2017

Codeception acceptance tests with Symfonys MasterSlaveConnection throws Exception

I'm using codeception (acceptance tests) in combination with the Symfony and Doctrine2 modules.

When I configure Symfony to use a single database connection, everything works fine and my tests finish. But as soon as I add database slave connections, the following exception appears and the test failes:

1) SomeCest: Some test
 Test  tests/acceptance/SomeCest.php:someTest

  [PHPUnit\Framework\Exception] Undefined property: Doctrine\DBAL\Connections\MasterSlaveConnection::$_conn

#1  /var/www/vendor/doctrine/dbal/lib/Doctrine/DBAL/Connections/MasterSlaveConnection.php:154
#2  Codeception\Subscriber\Module->before
#3  /var/www/vendor/symfony/symfony/src/Symfony/Component/EventDispatcher/EventDispatcher.php:184
#4  /var/www/vendor/symfony/symfony/src/Symfony/Component/EventDispatcher/EventDispatcher.php:46

I cannot understand how this error arises, because in the stated file (MasterSlaveConnection.php) the class is clearly extended from Connection, in which the property $_conn is defined.

Can someone help me with that? Is this a bug and I should open up a bug report on the codeception github page? Or am I doing something wrong? Thank you in advance!


acceptance.suite.yml:

actor: AcceptanceTester
modules:
    enabled:
        - Symfony:
            part: SERVICES
            environment: 'prod'
        - Doctrine2:
            depends: Symfony
            cleanup: false
        - WebDriver:
            url: 'http://localhost/'
            browser: phantomjs
            restart: true
            clear_cookies: true
            log_js_errors: true
            window_size: 1960x1080

app/config/config.yml with single database configuration:

doctrine:
    dbal:
        driver:   "%database_driver%"
        host:     "%database_host%"
        port:     "%database_port%"
        dbname:   "%database_name%"
        user:     "%database_user%"
        password: "%database_password%"
        charset:  UTF8

app/config/config.yml with multiple database configuration:

doctrine:
    dbal:
        driver:   "%database_driver%"
        host:     "%database_host%"
        port:     "%database_port%"
        dbname:   "%database_name%"
        user:     "%database_user%"
        password: "%database_password%"
        charset:  UTF8
        slaves:
            slave1:
                host:     "%database_host2%"
                dbname:   "%database_name%"
                user:     "%database_user%"
                password: "%database_password%"
            slave2:
                host:     "%database_host3%"
                dbname:   "%database_name%"
                user:     "%database_user%"
                password: "%database_password%"

I'm using symfony 2.8.25 and codeception 2.3.4

What is exactly mocking in unit testing?

I am trying to test an http server functionality and this is the first time I get exposed to the notions of mocks, stubs and fakes. I'm reading this book that it says mocking is describing the state of a complex object at a certain moment, like a snapshot, and testing the object as it is actually the real one. right? I understand this. what I don't understand is what is the point of writing unit tests and assertions of certain cases that we fully describe in the mock object. If we set the expectations of arguments and return values on the mocking object, and we test for those exact values, the test will always pass. Please correct me. I know I am missing something here.

Playframework test. FakeRequest sent with empty body always (scala)

I've been struggling several hours and every time I send a FakeRequest, it seems that the FakeApplication receives an empty body. However, if I try to run the play application and I send a normal request to localhost, everything works as expected, I receive the text I sent as a response.

My test code looks like:

      val controller = app.injector.instanceOf(classOf[CreateRecordController])
  val js = Json.obj()
  val result = controller.apply().apply(
    FakeRequest(POST, "/api/v1/record/")
      .withHeaders(Headers(CONTENT_TYPE -> "text/plain"))
      .withTextBody(js.toString())
  )

  val content = contentAsString(result)

  info.apply(s"content was $content")

The last statement prints: "content was" . Nothing else.

Am I missing something?

Play version: 2.6.2

JVM Cucumber: Running multiple testcase on a single step definition

I have a scenario in jvm cucmber as below

Given I have launched the <app_name> application page
And I fill out the <first_name> and <last_name> on the page
And I click Submit
And I am shown <message> on the <app_name> page based on <decision>
When I fill in username with value <username>
And I fill in password with value <password>
And I fill in confirmPassword with value <confirmPassword>
Then I should see the enroll button enabled for submission

In the above case, I want to submit the application only once as it is pretty much high time consuming. Once I submit only, I can get the enroll page as it is bounded by session token. But after that, I want to run multiple test with different sets of username, password and confirmpassword. Is it possible to have multiple test runs after we cross the particular submit step definition. Like a loop of test running.

How do I make R-R prediction with NARX in MATLAB?

I have 20 years data of rainfall and water level, and I would like to use NARX model to test the ability of it to forecast the water level.

I have gone through some of the teaching, whereby I need to train and test the data, but I am not sure I got the correct direction, and I am confused about the separation of data into training, validation and testing.

For example, I put the first 10 years of rainfall data (1996-2006) into NARX, trained it with selected parameters, and obtained the least error (record down the parameters) [testing stage]. Then I put the following 10 years (2006-2016) into the model again with that particular parameters [testing stage].?

OR inside the nntool GUI, there is a setting of which I can select the percentage of training, validation, and testing. For example (70-15-15), then I input all 20 years of data into the model at once, and the output shown is the final answer?

I am really confused on how to make a prediction and the data separation. I hope somebody out there can help me, in case anyone need any more information I can provide more in comment. Thank you in advance.

Espresso Dagger 2.11

Struggling to use Dagger 2 for UI testing powered by Espresso. I'm trying to generate a dedicated test @Component under androidTest directory but getting this error:

Error:Bad service configuration file, or exception thrown while constructing
Processor object: javax.annotation.processing.Processor: 
Provider dagger.android.processor.AndroidProcessor could not be instantiated:
java.lang.NoClassDefFoundError: com/google/common/collect/SetMultimap

Here's how dependencies look like:

androidTestCompile "com.google.dagger:dagger:2.11",
androidTestCompile "com.google.dagger:dagger-android:2.11"
androidTestCompile  "com.google.dagger:dagger-android-support:2.11"
androidTestAnnotationProcessor "com.google.dagger:dagger-compiler:2.11"
androidTestAnnotationProcessor "com.google.dagger:dagger-android-processor:2.11"

Have anyone faced with this and has a clue how to solve it?

Thanks.

Which type of Test is usefull for Jenkins Continous Integration (Spring Boot App)

My boss asked me to build some test on our Spring Boot application.

I'm asking myself which type of test should I implement, considering that the goal is to push the app on Jenkins that supports auto Testing.

Code based Test

@RunWith(SpringRunner.class)
@SpringBootTest
@AutoConfigureMockMvc
public class ConfigTagControllerTestReal {

    @Autowired
    MockMvc mockMvc;

    @Test
    public void shouldReturnTheTagName() throws Exception{

        this.mockMvc.perform(get("/configtag/librerie"))
                .andDo(print())
                .andExpect(status().isOk());

    }

Completely Mock Test

@RunWith(SpringRunner.class)
@WebMvcTest(value = ConfigTagController.class , secure = false)
public class ConfigTagControllerTestMocked {

    @Autowired
    private MockMvc mockMvc;

    @MockBean
    private ConfigTagService service;

    @Test
    public void shouldFindTheTagName() throws Exception{

        Collection<String> mockPaths= new ArrayList<>();

        ConfigTagEntity mockTag = new ConfigTagEntity("culo",mockPaths);

        Mockito.when(service.getByName(Mockito.anyString())).thenReturn(mockTag);

        RequestBuilder requestBuilder = MockMvcRequestBuilders.get("/configtag/culo")
                .accept(MediaType.APPLICATION_JSON);

        MvcResult result = mockMvc.perform(requestBuilder).andReturn();

    }

I'm very new in testing and i need to understand the working method