user1067800
user1067800

Reputation: 158

JHipster Unit Test Service Layer

I have a jhipster application that runs fine but I can't unit test it. It is configured to use mysql for development and production. I have updated the schema a few times (imported jdl) and used liquibase changelogs to keep it happy. I have added some functionality to the service layer and want to test it to ensure it behaves as expected. But when I run the unit test I am running into problems with liquibase. It complains about a "missing column [material_template_id] in table [dimension]" which by all accounts should be there. The entity dimension file has the column defined:

    <column name="material_template_id" type="bigint">
        <constraints nullable="true" />
    </column>

I have defined the unit test like this:

@RunWith(SpringRunner.class)
@SpringBootTest(classes = AlphaApp.class)
@Transactional
public class BomMaterialLineServiceImplTest {

    @Autowired
    BomMaterialLineServiceImpl bomLineSvc;

    @Before
    public void setUp() throws Exception {
    }

    @After
    public void tearDown() throws Exception {
    }

    @Test
    public void findBomMaterialLinesForBOM() {
    }
}

AlphaApp is the main file and is annotated as follows:

@ComponentScan
@EnableAutoConfiguration(exclude = {MetricFilterAutoConfiguration.class, MetricRepositoryAutoConfiguration.class})
@EnableConfigurationProperties({LiquibaseProperties.class, ApplicationProperties.class})
public class AlphaApp {

I have tried disabling liquibase in the test config file. Is there a standard way of implementing these tests with jhipster? It looks to me like the unit test is configured to use an in memory database as standard - is it this that is causing me grief?

Upvotes: 1

Views: 1909

Answers (1)

Ga&#235;l Marziou
Ga&#235;l Marziou

Reputation: 16294

Yes unit tests in JHipster use H2 but you can change it by editing src/test/resources/config/application.yml and changing datasource properties.

You can use testcontainers as explained in this article written by a JHipster team member.

Upvotes: 1

Related Questions